public ActionResult PrivateContentSelect(FileTypeModel model, string downloadType) { if (model.FileType != null || downloadType.LastIndexOf("--Delete") >= 0) { int index = downloadType.LastIndexOf("--"); string filename = downloadType.Substring(0, index) + ".fbx"; string selectionType = downloadType.Substring(index + 2); BlobManager blobManager = new BlobManager(); if (selectionType == "Download") { string downloadLink = blobManager.ConvertAndDownloadBlobFromUserContainer(User.Identity.Name, filename, model.FileType, Server.MapPath("~/UploadedFiles")); Response.Redirect(downloadLink); } else if (selectionType == "GeneralQR") { string downloadLink = blobManager.ConvertAndDownloadBlobFromUserContainer(User.Identity.Name, filename, model.FileType, Server.MapPath("~/UploadedFiles")); ViewBag.FileName = filename.Substring(0, filename.Length - 4) + model.FileType; return(DisplayQRCode(downloadLink)); } else if (selectionType == "MobileQR") { CloudBlobContainer container = blobManager.GetOrCreateBlobContainer(User.Identity.Name); CloudBlockBlob blob = container.GetBlockBlobReference(filename); string mobileLink = string.Empty; if (blob.Exists()) { mobileLink = blob.Uri.ToString(); } ViewBag.FileName = filename.Substring(0, filename.Length - 4) + model.FileType; return(DisplayQRCode(mobileLink)); } else if (selectionType == "Delete") { bool deleted = blobManager.DeleteBlobByNameInUserContainer(User.Identity.Name, filename); return(Index()); } return(View()); } else { ViewBag.Invalid = true; return(Index()); } }
public async Task <string> DownloadFile() { try { string reason = string.Empty; string fileUri = string.Empty; string downloadUrl = string.Empty; Tuple <string, string> validateUserInfo = null; //Get username and validate password from auth token validateUserInfo = await ValidateUser(); if (string.IsNullOrEmpty(validateUserInfo.Item2)) { //get file URI from HTTP headers if (Request.Headers.AllKeys.Contains("fileUri")) { fileUri = Request.Headers["fileUri"].ToString(); } //Parse Blob Container name and Blob Name string[] uriParts = fileUri.Split('/'); BlobManager blobManager = new BlobManager(); string blobName = uriParts[uriParts.Count() - 1]; string containerName = uriParts[uriParts.Count() - 2]; //make sure user is only trying to get their own or public file if (containerName.Equals(blobManager.FormatBlobContainerName(validateUserInfo.Item1)) || containerName.Equals("public")) { downloadUrl = blobManager.ConvertAndDownloadBlobFromUserContainer(containerName, blobName, ".obj", Server.MapPath("~/UploadedFiles")); if (downloadUrl.Contains("Error: ")) { //bad download attempt reason = downloadUrl; downloadUrl = string.Empty; } } else { reason = "Permission denied."; } } //return JSON return((JObject.Parse(FormatDownloadFileResult(reason, downloadUrl))).ToString()); } catch (Exception ex) { //return exception message return($"{{ \"Exception\": \"{ex.ToString()}\" }}"); } }