创建Azure的应用程序服务的blob容器 [英] Create blob container for Azure App Service

查看:277
本文介绍了创建Azure的应用程序服务的blob容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题升级MobileService天青应用服务。我有以下问题 Blob存储从Azure的应用服务这使访问我访问Blob存储。现在我想将图像保存到Blob存储,更新后的code是这样的:

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_AzureStorageConnectionString"));
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);
}

我不明白,为什么code。在失败等待container.CreateIfNotExistsAsync(); 。有人可以阐明正确的方法是如何创建的Blob存储和URI?以返回给客户端。

I cannot 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 return this to a client.

更新

下面是诊断概述堆栈输出。

Here is the stack-output from the diagnostic overview.

操作= blobStorageCreationController.ExecuteAsync,异常= Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(400)错误的请求。 ---> System.Net.WebException:远程服务器返回错误:(400)错误的请求。
     在Microsoft.WindowsAzure.Storage.Shared.Protocol.Htt$p$psponseParsers.ProcessExpectedStatus$c$cNoException[T](HttpStatus$c$c expectedStatus code,则httpStatus code actualStatus code,T retVal的,StorageCommandBase 1 CMD,异常前)在C:\\ Program Files文件(x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\Common\\Shared\\Protocol\\Htt$p$psponseParsers.Common.cs:line 50
     在Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.b__34(RESTCommand 1 CMD,HttpWebResponse RESP,异常前,的OperationContext CTX)在C:\\ Program Files文件(x86)的\\詹金斯\\工作区\\ release_dotnet_master \\ LIB \\ ClassLibraryCommon \\斑点\\ CloudBlobContainer。 CS:行2620
     在Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse [T](IAsyncResult的getResponseResult)在C:\\ Program Files文件(x86)的\\詹金斯\\工作区\\ release_dotnet_master \\ LIB \\ ClassLibraryCommon \\核心\\执行人\\ Executor.cs:行299
     ---内部异常堆栈跟踪的结尾---
     在Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult 1.End()在C:\\ Program Files文件(x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Util\\StorageAsyncResult.cs:line 77
     在Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.EndCreateIfNotExists(IAsyncResult的asyncResult)在C:\\ Program Files文件(x86)的\\詹金斯\\工作区\\ release_dotnet_master \\ LIB \\ ClassLibraryCommon \\斑点\\ CloudBlobContainer.cs:381线
     在Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions<> c__DisplayClass1 1.b__0(IAsyncResult的AR)在C:\\ Program Files文件(x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Util\\AsyncExtensions.cs:line 66
  ---从previous位置堆栈跟踪,其中引发异常的结尾---
     在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
     在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
     在System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
     在BCAppService.Controllers.blobStorageCreationController.d__1.MoveNext()在C:\\ BCApp_Runtime \\ BCAppService \\ \\控制器blobStorageController.cs:行248

Operation=blobStorageCreationController.ExecuteAsync, Exception=Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase 1 cmd, Exception ex) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\Common\Shared\Protocol\HttpResponseParsers.Common.cs:line 50 at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.b__34(RESTCommand 1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobContainer.cs:line 2620 at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 299 --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult 1.End() in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\StorageAsyncResult.cs:line 77 at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.EndCreateIfNotExists(IAsyncResult asyncResult) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobContainer.cs:line 381 at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1 1.b__0(IAsyncResult ar) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Util\AsyncExtensions.cs:line 66 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at BCAppService.Controllers.blobStorageCreationController.d__1.MoveNext() in C:\BCApp_Runtime\BCAppService\Controllers\blobStorageController.cs:line 248

有没有在创建时存在的斑点。

There does not exist a blob at the time of creation.

推荐答案

在有没有运行该code片段中的BLOB容器已经存在?

Did the blob container already exist upon running this code snippet?

如果是这样,你必须知道,删除操作是不是一个即时操作。一旦删除请求发出后,容器标记为被存储服务缺失,并应不再访问。它将被垃圾收集以后被删除。如果是这种情况下,你应该得到一个409(冲突)错误标记线。

If so, you must know that the delete operation is not an instant operation. Once the delete request is issued, the table container is marked for deletion by the storage service and shall be no longer accessible. It will be deleted by the garbage collector later on. If this is the case you should get a 409 (conflict) error in the marked line.

这篇关于创建Azure的应用程序服务的blob容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆