//[HttpPost("[action]")] public async Task <IActionResult> Upload(ICollection <IFormFile> files) { bool isUploaded = false; try { if (files.Count == 0) { return(BadRequest("No files received from the upload")); } if (storageConfig.AccountKey == string.Empty || storageConfig.AccountName == string.Empty) { return(BadRequest("sorry, can't retrieve your azure storage details from appsettings.js, make sure that you add azure storage details there")); } if (storageConfig.ImageContainer == string.Empty) { return(BadRequest("Please provide a name for your image container in the azure blob storage")); } foreach (var formFile in files) { if (StorageHelper.IsImage(formFile)) { if (formFile.Length > 0) { using (Stream stream = formFile.OpenReadStream()) { isUploaded = await StorageHelper.UploadFileToStorage(stream, formFile.FileName, storageConfig); } } } else { return(new UnsupportedMediaTypeResult()); } } if (isUploaded) { if (storageConfig.ThumbnailContainer != string.Empty) { return(new AcceptedAtActionResult("GetThumbNails", "Images", null, null)); } else { return(new AcceptedResult()); } } else { return(BadRequest("Look like the image couldnt upload to the storage")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Upload(ICollection <IFormFile> files) { bool isUploaded = false; try { if (files.Count == 0) { return(BadRequest("No files received from the upload")); } /* if (storageConfig.AccountKey == string.Empty || storageConfig.AccountName == string.Empty) * * return BadRequest("sorry, can't retrieve your azure storage details from appsettings.js, make sure that you add azure storage details there"); * * if (storageConfig.ImageContainer == string.Empty) * * return BadRequest("Please provide a name for your image container in the azure blob storage"); */ storageConfig.AccountName = "jasseraccount"; storageConfig.ImageContainer = "images"; storageConfig.AccountKey = "SMaAsGPvFmPO+tDDX5+JtqqRBplNzvgJS6tUj9NllEi5TUSRZb0y3HY7eedq9ac/+zwe/vW+onc68K0ugpF+jA=="; foreach (var formFile in files) { if (StorageHelper.IsImage(formFile)) { if (formFile.Length > 0) { using (Stream stream = formFile.OpenReadStream()) { isUploaded = await StorageHelper.UploadFileToStorage(stream, formFile.FileName, storageConfig); } } } else { return(new UnsupportedMediaTypeResult()); } } if (isUploaded) { storageConfig.ThumbnailContainer = "thumbnails"; return(new AcceptedAtActionResult("GetThumbNails", "Images", null, null)); } else { return(BadRequest("Look like the image couldnt upload to the storage")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult ValidateUpload(IFormFile files) { if (files == null) { return(BadRequest("No files received from the upload")); } if (_storageConfig.AccountKey == string.Empty || _storageConfig.AccountName == string.Empty) { return(BadRequest( "sorry, can't retrieve your azure storage details from appsettings.js, make sure that you add azure storage details there")); } if (_storageConfig.ImageContainer == string.Empty) { return(BadRequest("Please provide a name for your image container in the azure blob storage")); } if (!StorageHelper.IsImage(files)) { return(new UnsupportedMediaTypeResult()); } return(null); }
public async Task <IActionResult> Upload(ICollection <IFormFile> files) { bool isUploaded = false; try { if (files.Count == 0) { return(BadRequest("No files received from the upload.")); } if (storageConfig.AccountKey == string.Empty || storageConfig.AccountName == string.Empty) { return(BadRequest("Could not find Azure Storage AccountKey and AccountName.")); } if (storageConfig.ImageContainer == string.Empty) { return(BadRequest("Could not find Azure Blob Storage Image Container Name.")); } List <string> fileNames = new List <string>(); foreach (var formFile in files) { if (StorageHelper.IsImage(formFile)) { if (formFile.Length > 0) { using (Stream stream = formFile.OpenReadStream()) { string fileName = Guid.NewGuid().ToString() + Path.GetExtension(formFile.FileName); isUploaded = await StorageHelper.UploadFileToStorage(stream, fileName, storageConfig); fileNames.Add(fileName); } } } else { return(new UnsupportedMediaTypeResult()); } } if (isUploaded) { if (storageConfig.ThumbnailContainer != string.Empty) { // return new AcceptedAtActionResult("GetThumbNails", "Images", null, null); return(new ObjectResult(fileNames)); } else { return(new AcceptedResult()); } } else { return(BadRequest("Could not upload image to Azure Storage.")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }