Skip to content

Latest commit

 

History

History
132 lines (90 loc) · 6.25 KB

iot-hub-configure-file-upload-powershell.md

File metadata and controls

132 lines (90 loc) · 6.25 KB

title: Use the Azure PowerShell to configure file upload | Microsoft Docs description: How to use the Azure PowerShell cmdlets to configure your IoT hub to enable file uploads from connected devices. Includes information about configuring the destination Azure storage account. author: dominicbetts ms.service: iot-hub services: iot-hub ms.topic: conceptual ms.date: 08/08/2017 ms.author: dobett

Configure IoT Hub file uploads using PowerShell

[!INCLUDE iot-hub-file-upload-selector]

To use the file upload functionality in IoT Hub, you must first associate an Azure storage account with your IoT hub. You can use an existing storage account or create a new one.

To complete this tutorial, you need the following:

Sign in and set your Azure account

Sign in to your Azure account and select your subscription.

  1. At the PowerShell prompt, run the Connect-AzureRmAccount cmdlet:

    Connect-AzureRmAccount
  2. If you have multiple Azure subscriptions, signing in to Azure grants you access to all the Azure subscriptions associated with your credentials. Use the following command to list the Azure subscriptions available for you to use:

    Get-AzureRMSubscription

    Use the following command to select the subscription that you want to use to run the commands to manage your IoT hub. You can use either the subscription name or ID from the output of the previous command:

    Select-AzureRMSubscription `
        -SubscriptionName "{your subscription name}"

Retrieve your storage account details

The following steps assume that you created your storage account using the Resource Manager deployment model, and not the Classic deployment model.

To configure file uploads from your devices, you need the connection string for an Azure storage account. The storage account must be in the same subscription as your IoT hub. You also need the name of a blob container in the storage account. Use the following command to retrieve your storage account keys:

Get-AzureRmStorageAccountKey `
  -Name {your storage account name} `
  -ResourceGroupName {your storage account resource group}

Make a note of the key1 storage account key value. You need it in the following steps.

You can either use an existing blob container for your file uploads or create new one:

  • To list the existing blob containers in your storage account, use the following commands:

    $ctx = New-AzureStorageContext `
        -StorageAccountName {your storage account name} `
        -StorageAccountKey {your storage account key}
    Get-AzureStorageContainer -Context $ctx
  • To create a blob container in your storage account, use the following commands:

    $ctx = New-AzureStorageContext `
        -StorageAccountName {your storage account name} `
        -StorageAccountKey {your storage account key}
    New-AzureStorageContainer `
        -Name {your new container name} `
        -Permission Off `
        -Context $ctx

Configure your IoT hub

You can now configure your IoT hub to upload files to the IoT hub using your storage account details.

The configuration requires the following values:

  • Storage container: A blob container in an Azure storage account in your current Azure subscription to associate with your IoT hub. You retrieved the necessary storage account information in the preceding section. IoT Hub automatically generates SAS URIs with write permissions to this blob container for devices to use when they upload files.

  • Receive notifications for uploaded files: Enable or disable file upload notifications.

  • SAS TTL: This setting is the time-to-live of the SAS URIs returned to the device by IoT Hub. Set to one hour by default.

  • File notification settings default TTL: The time-to-live of a file upload notification before it is expired. Set to one day by default.

  • File notification maximum delivery count: The number of times the IoT Hub attempts to deliver a file upload notification. Set to 10 by default.

Use the following PowerShell cmdlet to configure the file upload settings on your IoT hub:

Set-AzureRmIotHub `
    -ResourceGroupName "{your iot hub resource group}" `
    -Name "{your iot hub name}" `
    -FileUploadNotificationTtl "01:00:00" `
    -FileUploadSasUriTtl "01:00:00" `
    -EnableFileUploadNotifications $true `
    -FileUploadStorageConnectionString "DefaultEndpointsProtocol=https;AccountName={your storage account name};AccountKey={your storage account key};EndpointSuffix=core.windows.net" `
    -FileUploadContainerName "{your blob container name}" `
    -FileUploadNotificationMaxDeliveryCount 10

Next steps

For more information about the file upload capabilities of IoT Hub, see Upload files from a device.

Follow these links to learn more about managing Azure IoT Hub:

To further explore the capabilities of IoT Hub, see: