MobileServiceをAzure App Serviceにアップグレードする際にいくつかの問題がありました。私は以下の質問Blob storage access from Azure App Serviceを持っていたので、BLOBストレージにアクセスすることができました。Azure Appサービス用のBlobコンテナの作成
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);
}
コードがawait container.CreateIfNotExistsAsync();
で失敗した理由を私は理解することはできません。今、私は更新されたコードは次のようであるBLOBストレージに画像を保存したかったです。正しい方法でBLOBストレージとURIを作成する方法を誰かが明確にすることはできますか?これをクライアントに返す。ここ
更新
診断概要からスタックが出力されます。
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
作成時にブロブが存在しません。
作成しようとしているコンテナの名前を教えてください。 –
この記事をチェック:http://stackoverflow.com/questions/19599819/azure-blob-400-bad-request-on-creattion-of-containerこれが問題かどうかを確認してください。 –
@AlexBelotserkovskiyそれはあなたが名前を言ったとおりでした。サービスをアップグレードした後、Idをintから文字列に変更しました。文字列に問題があった '_'がありました。私は明日の質問を削除しますが、これは何も貢献しません。 – JTIM