You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Make sure that port 8883 is open in your firewall. The device sample in this article uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](iot-hub-mqtt-support.md#connecting-to-iot-hub).
36
36
@@ -40,13 +40,13 @@ At the end of this tutorial you run the Python console app:
40
40
41
41
In this section, you create the device app to upload a file to IoT hub.
42
42
43
-
1. At your command prompt, run the following command to install the **azure-iot-device** package:
43
+
1. At your command prompt, run the following command to install the **azure-iot-device** package. You use this package to coordinate the file upload with your IoT hub.
44
44
45
45
```cmd/sh
46
46
pip install azure-iot-device
47
47
```
48
48
49
-
1. At your command prompt, run the following command to install the **azure.storage.blob** package.
49
+
1. At your command prompt, run the following command to install the [**azure.storage.blob**](https://pypi.org/project/azure-storage-blob/) package. You use this package to perform the file upload.
50
50
51
51
```cmd/sh
52
52
pip install azure.storage.blob
@@ -69,7 +69,7 @@ In this section, you create the device app to upload a file to IoT hub.
69
69
PATH_TO_FILE = r"[Full path to local file]"
70
70
```
71
71
72
-
1. In your file, replace `[Device Connection String]` with the connection string of your IoT hub device. Replace `[Full path to file]` with the path to the test file that you created, or any file on your device that you want to upload.
72
+
1. In your file, replace `[Device Connection String]` with the connection string of your IoT hub device. Replace `[Full path to local file]` with the path to the test file that you created or any file on your device that you want to upload.
73
73
74
74
1. Create a function to upload the file to blob storage:
75
75
@@ -101,6 +101,8 @@ In this section, you create the device app to upload a file to IoT hub.
101
101
return (False, ex)
102
102
```
103
103
104
+
This function parses the *blob_info* structure passed into it to create a URL that it uses to initialize an [azure.storage.blob.BlobClient](https://docs.microsoft.com/python/api/azure-storage-blob/azure.storage.blob.blobclient?view=azure-python). Then it uploads your file to Azure blob storage using this client.
105
+
104
106
1. Add the following code to connect the client and upload the file:
105
107
106
108
```python
@@ -159,6 +161,12 @@ In this section, you create the device app to upload a file to IoT hub.
159
161
#loop.close()
160
162
```
161
163
164
+
This code creates an asynchronous **IoTHubDeviceClient** and uses the the following APIs to manage the file upload with your IoT hub:
165
+
166
+
* **get_storage_info_for_blob** gets information from your IoT hub about the linked Storage Account you created previously. This includes the hostname, container name, blob name and a SAS token. This information is passed to the **store_blob** function (in the previous step), so the **BlobClient** in that function can authenticate with Azure storage. The **get_storage_info_for_blob** method also returns a correlation_id, which is used in the **notify_blob_upload_status** method. The correlation_id is IoT Hub's way of marking which blob you are working on.
167
+
168
+
* **notify_blob_upload_status** notifies IoT Hub of the status of your blob storage operation. You pass it the correlation_id obtained by the **get_storage_info_for_blob** method. It's used by IoT Hub to notify any service that might be listening for a notification on the status of the file upload task.
169
+
162
170
1. Save and close the **UploadFile.py** file.
163
171
164
172
## Run the application
@@ -188,3 +196,9 @@ In this tutorial, you learned how to use the file upload capabilities of IoT Hub
188
196
* [Introduction to C SDK](iot-hub-device-sdk-c-intro.md)
189
197
190
198
* [Azure IoT SDKs](iot-hub-devguide-sdks.md)
199
+
200
+
Learn more about Azure Blob Storage with the following links:
* An active Azure account. (If you don't have an account, you can create a [free account](https://azure.microsoft.com/pricing/free-trial/) in just a couple of minutes.)
14
+
15
+
*[Python version 3.7 or later](https://www.python.org/downloads/) is recommended. Make sure to use the 32-bit or 64-bit installation as required by your setup. When prompted during the installation, make sure to add Python to your platform-specific environment variable. For other versions of Python supported, see [Azure IoT Device Features](https://github.com/Azure/azure-iot-sdk-python/tree/master/azure-iot-device#azure-iot-device-features) in the SDK documentation.
16
+
17
+
> [!IMPORTANT]
18
+
> Because the device code in this article uses the asynchronous API, you cannot use Python 2.7.
0 commit comments