خرید بک لینک

Vote count: 0

I have had some issues with upgrading a MobileService to Azure App Service. I had the following question Blob storage access from Azure App Service which enabled me to access the blob storage. Now I wanted to save an image to the blob storage, which the updated code is like this:

string cloud = "";

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("battlecrestimage_AzureStorageCoectionString"));
cloud = storageAccount.BlobEndpoint.ToString() + "        " + storageAccount.BlobStorageUri.ToString();

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
if (item.ContainerName != null)
 {
     // Set the BLOB store container name on the item, which must be lowercase.
     item.ContainerName = item.ContainerName.ToLower();

     // Create a container, if it doesn't already exist.
     CloudBlobContainer container = blobClient.GetContainerReference(item.ContainerName);

     try
     {
          await container.DeleteIfExistsAsync();
          telemetry.TrackTrace("Deleted.");
     }
     catch 
     {
          telemetry.TrackTrace("Could not DeleteIfExist.");
     }
     await container.CreateIfNotExistsAsync(); //Code fails at this point

     // Create a shared access permission policy. 
     BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

     // Enable anonymous read access to BLOBs.
     containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
     container.SetPermissions(containerPermissions);

     // Define a policy that gives write access to the container for 5 minutes.                                   
     SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy()
     {
         SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5),
         Permissions = SharedAccessBlobPermissions.Write
     };

     // Get the SAS as a string.
     item.SasQueryString = container.GetSharedAccessSignature(sasPolicy);

     // Set the URL used to store the image.
     item.ImageUri = string.Format("{0}{1}/{2}", storageAccount.BlobEndpoint,
     item.ContainerName, item.ResourceName);
}

I caot understand why the code fails at await container.CreateIfNotExistsAsync();. Can somebody clarify how the correct way is to create the blob storage and uri? To retu this to a client.

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 16 ارديبهشت 1395 ساعت: 19:28

صفحه بندی