| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 
 | using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
 
namespace WebRole1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
 
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
 
            return View();
        }
 
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
 
            return View();
        }
        BlobStorageServices _blobStorageService = new BlobStorageServices();
 
        public ActionResult Upload()
        {
            CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
            List<String> blobs = new List<string>();
            foreach (var blobItem in blobContainer.ListBlobs())
            {
                blobs.Add(blobItem.Uri.ToString());
            }
            return View(blobs);
        }
        [HttpPost]
        public ActionResult Upload(HttpPostedFileBase image)
 
        {
           if (image.ContentLength > 0) // ----- ligne provoquant une exception  -----
            { 
                CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
                CloudBlockBlob blob = blobContainer.GetBlockBlobReference(image.FileName);
                blob.UploadFromStream(image.InputStream);
        }
        return RedirectToAction("Upload");
    }
    [HttpPost]        
        public string DeleteImage(string name)
        {
        Uri uri = new Uri(name);
        string filename = System.IO.Path.GetFileName(uri.LocalPath);
        CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
        CloudBlockBlob blob = blobContainer.GetBlockBlobReference(filename);
 
        blob.Delete();
        return "Fichier effacé";
    }
}
} | 
Partager