Skip to content

Commit e8f63e7

Browse files
committed
added comments, fixed pre-reqs
1 parent 5d25b2d commit e8f63e7

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

articles/iot-hub/iot-hub-python-python-file-upload.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ At the end of this tutorial you run the Python console app:
3030

3131
## Prerequisites
3232

33-
[!INCLUDE [iot-hub-include-python-v2-installation-notes](../../includes/iot-hub-include-python-v2-installation-notes.md)]
33+
[!INCLUDE [iot-hub-include-python-v2-async-installation-notes](../../includes/iot-hub-include-python-v2-async-installation-notes.md)]
3434

3535
* 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).
3636

@@ -40,13 +40,13 @@ At the end of this tutorial you run the Python console app:
4040

4141
In this section, you create the device app to upload a file to IoT hub.
4242

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.
4444

4545
```cmd/sh
4646
pip install azure-iot-device
4747
```
4848
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.
5050
5151
```cmd/sh
5252
pip install azure.storage.blob
@@ -69,7 +69,7 @@ In this section, you create the device app to upload a file to IoT hub.
6969
PATH_TO_FILE = r"[Full path to local file]"
7070
```
7171
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.
7373
7474
1. Create a function to upload the file to blob storage:
7575
@@ -101,6 +101,8 @@ In this section, you create the device app to upload a file to IoT hub.
101101
return (False, ex)
102102
```
103103
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+
104106
1. Add the following code to connect the client and upload the file:
105107
106108
```python
@@ -159,6 +161,12 @@ In this section, you create the device app to upload a file to IoT hub.
159161
#loop.close()
160162
```
161163
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+
162170
1. Save and close the **UploadFile.py** file.
163171
164172
## Run the application
@@ -188,3 +196,9 @@ In this tutorial, you learned how to use the file upload capabilities of IoT Hub
188196
* [Introduction to C SDK](iot-hub-device-sdk-c-intro.md)
189197
190198
* [Azure IoT SDKs](iot-hub-devguide-sdks.md)
199+
200+
Learn more about Azure Blob Storage with the following links:
201+
202+
* [Azure Blob Storage documentation](https://docs.microsoft.com/azure/storage/blobs/)
203+
204+
* [Azure Blob Storage for Python API documentation](https://docs.microsoft.com/python/api/overview/azure/storage-blob-readme?view=azure-python)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: include file
3+
description: include file
4+
services: iot-hub
5+
author: robinsh
6+
ms.service: iot-hub
7+
ms.topic: include
8+
ms.date: 03/30/2020
9+
ms.author: robinsh
10+
ms.custom: include file
11+
---
12+
13+
* 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

Comments
 (0)