//Create a Blob with the picture in CloudDataBase and save the the link of ImagePath in Image object and return the object async private Task <Image> AddNewBlob(Image image, HttpPostedFileBase imageFile) { BlobStrorageServices blobStorageService = new BlobStrorageServices(); CloudBlobContainer blobContainer = blobStorageService.GetCloudBlobContainer(); CloudBlockBlob blob = blobContainer.GetBlockBlobReference(imageFile.FileName); await blob.UploadFromStreamAsync(imageFile.InputStream); image.ImagePath = blob.Uri.ToString(); return(image); }
public void DeleteImage(int id) { Image image = db.Images.Find(id); BlobStrorageServices blobStorageService = new BlobStrorageServices(); CloudBlobContainer blobContainer = blobStorageService.GetCloudBlobContainer(); CloudBlob blob = blobContainer.GetBlobReference(image.ImagePath); blob.DeleteIfExistsAsync(); db.Images.Remove(image); db.SaveChangesAsync(); }