Wednesday, 3 August 2016

File upload from device in IoT Hub ("Message":"ErrorCode:InvalidStorageEndpointProperty;BadRequest")

I was recently trying out the newly introduced feature of "File Upload" in IoT Hub and ran into an interesting issue. I followed every step mentioned in the Azure documentation for the code creation and configured the file upload on IoT Hub using the prescribed link

The code kept failing with following error:

Exception: Exception caught: 'System.ArgumentException' in mscorlib.dll ("{"Message":"ErrorCode:InvalidStorageEndpointProperty;BadRequest",
 "ExceptionMessage":"Tracking ID:98cf5df7f44c4d0f9a463b1cec691e14-G:4-TimeStamp:08/03/2016 05:59:50"}").
 Exception caught: 'System.ArgumentException' in mscorlib.dll
 ("{"Message":"ErrorCode:InvalidStorageEndpointProperty;BadRequest",
 "ExceptionMessage":"Tracking ID:98cf5df7f44c4d0f9a463b1cec691e14-G:4-TimeStamp:08/03/2016 05:59:50"}")

As it turns out there is a bug in the current Azure Portal UI that does not set the storage account details and container name in the "File Upload" options. It shows the UI as following:


You can verify that by getting the details of the resource through PowerShell.

PS C:\windows\system32> Login-AzureRmAccount
PS C:\windows\system32> $res = Get-AzureRmResource -ResourceId /subscriptions/XYZ/resou
rceGroups/StreamAnalytics-Default-East-US/providers/Microsoft.Devices/IotHubs/123iothub
PS C:\windows\system32> $res

Name              : 123iothub
ResourceId        : /subscriptions/XYZ/resourceGroups/StreamAnalytics-Default-East-US/
                    providers/Microsoft.Devices/IotHubs/123iothub
ResourceName      : 123iothub
ResourceType      : Microsoft.Devices/IotHubs
ResourceGroupName : StreamAnalytics-Default-East-US
Location          : eastus
SubscriptionId    :
XYZ
Tags              : {}
Properties        : @{state=Active; provisioningState=Succeeded; hostName=123iothub.azure-devices.net;
                    eventHubEndpoints=; storageEndpoints=; messagingEndpoints=; enableFileUploadNotifications=True;
                    cloudToDevice=; operationsMonitoringProperties=; features=DeviceManagement; generationNumber=0}
ETag              : AAAAAABLpj8=
Sku               : @{name=F1; tier=Free; capacity=1}

PS C:\windows\system32> $res.Properties

state                          : Active
provisioningState              : Succeeded
hostName                       : 123iothub.azure-devices.net
eventHubEndpoints              : @{events=; operationsMonitoringEvents=}
storageEndpoints               : @{$default=}
messagingEndpoints             : @{fileNotifications=}
enableFileUploadNotifications  : True
cloudToDevice                  : @{maxDeliveryCount=10; defaultTtlAsIso8601=PT1H; feedback=}
operationsMonitoringProperties : @{events=}
features                       : DeviceManagement
generationNumber               : 0

PS C:\windows\system32> $res.Properties.storageEndpoints
$default
--------
@{sasTtlAsIso8601=PT2H; connectionString=; containerName=}

So, till the UI gets fixed, the work around is to either to update through PowerShell or use a wonderful site called https://resources.azure.com



Once you have updated the details, the UI starts to show the assigned storage account as well. Of course, the file upload functionality starts to work as well.




2 comments:

  1. Sample of storage connection string ?

    ReplyDelete
  2. Whauw, thanks!!! I'm sure you just saved me days of debugging.

    ReplyDelete