Upload file to Azure

In NuGet to install:
WindowsAzure.Storage
Microsoft.Azure.Management.Storage   ?? not need
Microsoft.WindowsAzure.ConfigurationManager
 
		[HttpPost]
		public virtual ActionResult UploadFileToAzure()
		{
			bool isUploaded = false;
			string path = ConfigurationManager.AppSettings["uploadAzurePath_Patient"];
			HttpPostedFileBase file = Request.Files[0];

			string url = this._uploadServices.UploadToAzureStorage(file, path);
			if (url != null)
			{
				isUploaded = true;
				string message = "100% complete";
				return Json(new
				{
					statusCode = 200,
					status = "File uploaded.",
					file = url,
					isUploaded = isUploaded,
					message = message
				}, "text/html");

			}
			else
				return Json(new
				{
					statusCode = 500,
					status = "Error uploading image.",
					file = string.Empty,
					isUploaded = isUploaded
				}, "text/html");


		}
		
		
	   [HttpDelete]
		public virtual ActionResult DeleteFile(string fileURL)
		{
			string path = ConfigurationManager.AppSettings["uploadAzurePath_Patient"];
			if (this._uploadServices.DeleteFromAzureStorage(fileURL, path))
				return Json(new { message = "The file has delete !" }, "text/html");
			else
				return Json(new { message = "Error" }, "text/html");
		}
		

Last updated

Was this helpful?