#azure #azure-iot-hub #azure-iot-sdk
#лазурный #azure-iot-hub #azure-iot-sdk
Вопрос:
Я включил частную конечную точку для iot-концентратора и учетной записи хранилища Azure и ограничил общедоступный трафик, когда я загружаю файл, он успешно загружается, но при вызове метода CompleteFileUploadAsync клиента устройства я получаю ошибку 403 как запрещенную. Но при передаче isSuccess = false, который работает с текущей конфигурацией, я изменил Разрешенный доступ с «Все сети» на «Все сети», после чего он заработал.
Я хочу убедиться, что он уведомляет в частной сети при успешной загрузке файла, так как он работает при сбое загрузки файла.
Код:
private static async Task SendToBlobAsync(DeviceClient deviceClient, string fileName)
{
Console.WriteLine("Uploading file: {0}", fileName);
var watch = System.Diagnostics.Stopwatch.StartNew();
var sas = await deviceClient.GetFileUploadSasUriAsync(new FileUploadSasUriRequest { BlobName = fileName });
var blob = new CloudBlockBlob(sas.GetBlobUri());
await blob.UploadFromFileAsync(fileName);
await deviceClient.CompleteFileUploadAsync(new FileUploadCompletionNotification { CorrelationId = sas.CorrelationId, IsSuccess = true });
watch.Stop();
Console.WriteLine("Time to upload file: {0}msn", watch.ElapsedMilliseconds);
}
Метод, выдающий приведенное ниже сообщение об ошибке :
{
"Message":"{"errorCode":400020,"trackingId":"72f35ff2b08f4312bc0e9f9d36be1061-G:0-TimeStamp:02/23/2021 14:24:46","message":"BadRequest","timestampUtc":"2021-02-23T14:24:46.3420546Z"}",
"ExceptionMessage":"ErrorCode: InvalidStorageEndpointOrBlobrnMessage: Storage endpoint '$default' or blob name device001/image.jpg is invalidrnTimestamp: 02/23/2021 14:24:46rnTracking ID: 72f35ff2b08f4312bc0e9f9d36be1061-G:0-TimeStamp:02/23/2021 14:24:46rnPublic Message: rnPublic Info: nullrnException: Microsoft.Azure.Devices.Common.Core.Exceptions.IotHubException: Storage endpoint '$default' or blob name device001/image.jpg is invalid ---> Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (403) Forbidden. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.rn at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase`1 cmd, Exception ex)rn at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<>c__DisplayClass22.<FetchAttributesImpl>b__21(RESTCommand`1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx)rn at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)rn --- End of inner exception stack trace ---rn at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)rn at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass7.<CreateCallbackVoid>b__5(IAsyncResult ar)rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Runtime.FileUpload.IotHubFileUploadManager.<GenerateFileUploadNotificationAsync>d__10.MoveNext() in C:\source\gateway\runtime\FileUpload\IotHubFileUploadManager.cs:line 153rn --- End of inner exception stack trace ---rn at Microsoft.Azure.Devices.Gateway.Runtime.FileUpload.IotHubFileUploadManager.<GenerateFileUploadNotificationAsync>d__10.MoveNext() in C:\source\gateway\runtime\FileUpload\IotHubFileUploadManager.cs:line 180rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Runtime.Http.HttpRuntimeProvider.<UpdateAndNotifyFileUploadStatusAsync>d__41.MoveNext() in C:\source\gateway\runtime\Http\HttpRuntimeProvider.cs:line 1215rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Runtime.Http.HttpRuntimeActionResult`1.<ExecuteAsync>d__7.MoveNext() in C:\source\gateway\mgmt\Http\HttpRuntimeActionResult.cs:line 153rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Management.ActionFilters.GlobalActionFilter.<ExecuteActionFilterAsync>d__0.MoveNext() in C:\source\gateway\mgmt\ActionFilters\GlobalActionFilter.cs:line 42rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()",
"ExceptionType":"Microsoft.Azure.Devices.Common.Core.Exceptions.IotHubException",
"StackTrace":" at Microsoft.Azure.Devices.Gateway.Runtime.FileUpload.IotHubFileUploadManager.<GenerateFileUploadNotificationAsync>d__10.MoveNext() in C:\source\gateway\runtime\FileUpload\IotHubFileUploadManager.cs:line 180rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Runtime.Http.HttpRuntimeProvider.<UpdateAndNotifyFileUploadStatusAsync>d__41.MoveNext() in C:\source\gateway\runtime\Http\HttpRuntimeProvider.cs:line 1215rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Runtime.Http.HttpRuntimeActionResult`1.<ExecuteAsync>d__7.MoveNext() in C:\source\gateway\mgmt\Http\HttpRuntimeActionResult.cs:line 153rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Management.ActionFilters.GlobalActionFilter.<ExecuteActionFilterAsync>d__0.MoveNext() in C:\source\gateway\mgmt\ActionFilters\GlobalActionFilter.cs:line 42rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()",
"InnerException":{
"Message":"An error has occurred.",
"ExceptionMessage":"The remote server returned an error: (403) Forbidden.",
"ExceptionType":"Microsoft.WindowsAzure.Storage.StorageException",
"StackTrace":" at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)rn at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass7.<CreateCallbackVoid>b__5(IAsyncResult ar)rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at Microsoft.Azure.Devices.Gateway.Runtime.FileUpload.IotHubFileUploadManager.<GenerateFileUploadNotificationAsync>d__10.MoveNext() in C:\source\gateway\runtime\FileUpload\IotHubFileUploadManager.cs:line 153",
"InnerException":{
"Message":"An error has occurred.",
"ExceptionMessage":"The remote server returned an error: (403) Forbidden.",
"ExceptionType":"System.Net.WebException",
"StackTrace":" at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatusCodeNoException[T](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase`1 cmd, Exception ex)rn at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<>c__DisplayClass22.<FetchAttributesImpl>b__21(RESTCommand`1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx)rn at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)"
}
}
}
Комментарии:
1. привет, похоже, это сообщение об ошибке находится в формате JSON. не могли бы вы, пожалуйста, отформатировать его как таковой и заменить
rn
на настоящие новые строки? в данный момент это довольно трудно читать. ваше здоровье2. Я столкнулся с аналогичной проблемой с Java sdk