示例#1
0
        //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);
        }
示例#2
0
        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();
        }