public ActionResult Upload(HttpPostedFileBase file) { ClaimsPrincipal cp = ClaimsPrincipal.Current; string email = cp.Identity.Name.ToString(); LOGGER.Info("Document upload link called by " + email + " with the filename " + file.FileName); // Verify that the user selected a file if (file != null && file.ContentLength > 0) { try { LOGGER.Info("Document upload to azure blob container started for " + email + " with the filename " + file.FileName); CloudBlobContainer _azureBlob = AzureBlob.AzureBlobContainer(DocContainerName); CloudBlockBlob blockBlob = _azureBlob.GetBlockBlobReference(file.FileName); using (var fileStream = file.InputStream) { blockBlob.UploadFromStream(fileStream); } LOGGER.Info("Document upload to azure blob container completed successfully for " + email + " with the filename " + file.FileName); ViewBag.Message = "File uploaded successfully"; } catch (Exception ex) { LOGGER.Error("Document uplod has failed for " + email + " with the filename " + file.FileName + "due to " + ex.Message.ToString()); ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Message = "You have not specified a file."; } return(View("UploadDocument")); }
public ActionResult Upload(HttpPostedFileBase file) { ClaimsPrincipal cp = ClaimsPrincipal.Current; string email = cp.Identity.Name.ToString(); LOGGER.Info("video upload link called by " + email + " with the filename " + file.FileName); if (file != null && file.ContentLength > 0) { try { LOGGER.Info("video upload to azure blob container started for " + email + "with the filename " + file.FileName); string message = ""; CloudBlobContainer _azureBlob = AzureBlob.AzureBlobContainer(VideoContainerName); CloudBlockBlob blockBlob = _azureBlob.GetBlockBlobReference(file.FileName); using (var fileStream = file.InputStream) { try { blockBlob.UploadFromStream(fileStream, accessCondition: Microsoft.WindowsAzure.Storage.AccessCondition.GenerateIfNoneMatchCondition("*")); LOGGER.Info("video upload to azure blob container completed successfully for " + email + " with the filename " + file.FileName); message = "File Uploaded Successfully"; } catch (StorageException ex) { if (ex.RequestInformation.HttpStatusCode == (int)System.Net.HttpStatusCode.Conflict) { LOGGER.Info("The video is already exisit in the " + email + " with the filename " + file.FileName); message = "File Already Exisit"; } } } ViewBag.Message = message; } catch (Exception ex) { LOGGER.Error("video uplod has failed for " + email + " with the filename " + file.FileName + "due to " + ex.Message.ToString()); ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Message = "You have not specified a file."; } return(View("UploadVideo")); }