Azure Blob 400 Bad request on Creation of container

后端 未结 12 2464
夕颜
夕颜 2020-12-15 16:26

I\'m developing an ASP.Net MVC 4 app and I\'m using Azure Blob to store the images that my users are going to upload. I have the following code:

 var storag         


        
12条回答
  •  囚心锁ツ
    2020-12-15 16:44

    it's necessary view the httpstatusmessage in exception: in my case the error was because The requested URI does not represent any resource on the server.

    so i've seen that my BlobContainerName not contains the right container (or not exists)

    CloudBlobContainer container = > blobClient.GetContainerReference(BlobContainerName);
    

    other case i've seen is the wrong name of container. blobcontainername that must be a name like "mycontainer1" or "mycontainer2" and so on

    here the code to add container

    try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
    
                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    
                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference(BlobContainerName);
    
                container.CreateIfNotExists();
    
               //creo se non esiste e aggiungo i permessi
                BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
                containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                container.SetPermissions(containerPermissions);
    
                // Retrieve reference to a blob named "myblob".
                CloudBlockBlob blockBlob = container.GetBlockBlobReference(Filename); 
    
                blockBlob.UploadFromStream(inFileUpload);
            }
            catch (Exception ex)
            {
                return "";
            }
    

提交回复
热议问题