Skip to content

Commit b9af409

Browse files
committed
Edits
1 parent 72985f4 commit b9af409

File tree

5 files changed

+63
-57
lines changed

5 files changed

+63
-57
lines changed

articles/iot-hub/how-to-file-upload.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ms.custom: [amqp, mqtt, "Role: Cloud Development", "Role: IoT Device"]
1616

1717
This article demonstrates how to:
1818

19-
* Use [file upload capabilities of IoT Hub](iot-hub-devguide-file-upload.md) to upload a file to [Azure blob storage](../storage/index.yml), using an Azure IoT device and service SDKs.
19+
* Use [file upload capabilities of IoT Hub](iot-hub-devguide-file-upload.md) to upload a file to [Azure Blob Storage](../storage/index.yml), using an Azure IoT device and service SDKs.
2020
* Notify IoT Hub that the file was successfully uploaded and create a backend service to receive file upload notifications from IoT Hub.
2121

2222
The [Send telemetry from a device to an IoT hub](../iot/tutorial-send-telemetry-iot-hub.md?toc=/azure/iot-hub/toc.json&bc=/azure/iot-hub/breadcrumb/toc.json&pivots=programming-language-csharp) quickstart and [Send cloud-to-device messages with IoT Hub](c2d-messaging-dotnet.md) article show the basic device-to-cloud and cloud-to-device messaging functionality of IoT Hub. The [Configure Message Routing with IoT Hub](tutorial-routing.md) article shows a way to reliably store device-to-cloud messages in Microsoft Azure blob storage. However, in some scenarios, you can't easily map the data your devices send into the relatively small device-to-cloud messages that IoT Hub accepts. For example:
@@ -32,8 +32,8 @@ For more information, see:
3232

3333
* [Overview of file uploads with IoT Hub](iot-hub-devguide-file-upload.md)
3434
* [Configure IoT Hub file uploads](iot-hub-configure-file-upload.md)
35-
* [Azure blob storage documentation](../storage/blobs/storage-blobs-introduction.md)
36-
* [Azure blob storage API reference](../storage/blobs/reference.md)
35+
* [Azure Blob Storage documentation](../storage/blobs/storage-blobs-introduction.md)
36+
* [Azure Blob Storage API reference](../storage/blobs/reference.md)
3737
* [Azure IoT SDKs](iot-hub-devguide-sdks.md)
3838

3939
[!INCLUDE [iot-hub-include-x509-ca-signed-file-upload-support-note](../../includes/iot-hub-include-x509-ca-signed-file-upload-support-note.md)]

includes/iot-hub-howto-file-upload-dotnet.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ ms.date: 07/01/2024
1111
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1212
---
1313

14+
This how-to contains two sections:
15+
16+
* Upload a file from a device application
17+
* Receive file upload notification in a backend application
18+
1419
## Upload a file from a device application
1520

16-
Follow this procedure for uploading a file from a device to IoT Hub:
21+
Follow this procedure to upload a file from a device to IoT Hub:
1722

1823
* Connect to IoT Hub
1924
* Get a SAS URI from IoT Hub
2025
* Upload the file to Azure storage
2126
* Notify IoT Hub that it completed the upload
2227

23-
The [DeviceClient](/dotnet/api/microsoft.azure.devices.client.deviceclient) class contains methods that a device can use to upload files to IoT Hub.
24-
2528
### Connect to IoT Hub
2629

27-
Supply the IoT Hub primary connection string to `DeviceClient` using the [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.deviceclient.createfromconnectionstring?#microsoft-azure-devices-client-deviceclient-createfromconnectionstring(system-string)) method. `AMQP` is the default transport protocol.
30+
Supply the IoT Hub primary connection string to [DeviceClient](/dotnet/api/microsoft.azure.devices.client.deviceclient) using the [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.deviceclient.createfromconnectionstring?#microsoft-azure-devices-client-deviceclient-createfromconnectionstring(system-string)) method. `AMQP` is the default transport protocol.
2831

2932
``` csharp
3033
static string connectionString = "{IoT Hub connection string}";
@@ -35,8 +38,6 @@ deviceClient = DeviceClient.CreateFromConnectionString(connectionString);
3538

3639
Call [GetFileUploadSasUriAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.getfileuploadsasuriasync) to get a file upload SAS URI, which the Azure Storage SDK can use to upload a file to blob for this device.
3740

38-
For example:
39-
4041
```csharp
4142
const string filePath = "TestPayload.txt";
4243
using var fileStreamSource = new FileStream(filePath, FileMode.Open);
@@ -54,11 +55,11 @@ Uri uploadUri = sasUri.GetBlobUri();
5455

5556
Create a [blockBlobClient](/dotnet/api/azure.storage.blobs.specialized.blockblobclient) object, passing a file upload URI.
5657

57-
Use the [UploadAsync](/dotnet/api/azure.storage.blobs.specialized.blockblobclient.uploadasync?#azure-storage-blobs-specialized-blockblobclient-uploadasync(system-io-stream-azure-storage-blobs-models-blobuploadoptions-system-threading-cancellationtoken)) method to upload a file to Azure storage, passing the SAS URI.
58+
Use the [UploadAsync](/dotnet/api/azure.storage.blobs.specialized.blockblobclient.uploadasync?#azure-storage-blobs-specialized-blockblobclient-uploadasync(system-io-stream-azure-storage-blobs-models-blobuploadoptions-system-threading-cancellationtoken)) method to upload a file to Blob Storage, passing the SAS URI.
5859

59-
The Azure blob client always uses HTTPS as the protocol to upload the file Azure storage.
60+
The Azure Blob client always uses HTTPS as the protocol to upload the file to Azure Storage.
6061

61-
In this example, `BlockBlobClient` is passed the SAS URI to create an Azure storage block blob client and uploads the file:
62+
In this example, `BlockBlobClient` is passed the SAS URI to create an Azure Storage block blob client and uploads the file:
6263

6364
```csharp
6465
var blockBlobClient = new BlockBlobClient(uploadUri);
@@ -110,9 +111,9 @@ static string connectionString = "{IoT Hub connection string}";
110111
serviceClient = ServiceClient.CreateFromConnectionString(connectionString);
111112
```
112113

113-
### Receive the file upload notification
114+
### Receive file upload notification in a backend application
114115

115-
You can create a separate backend service to receive file upload notifications.
116+
You can create a separate backend application to receive file upload notifications.
116117

117118
The [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient) class contains methods that services can use to receive file upload notification.
118119

includes/iot-hub-howto-file-upload-java.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@ ms.date: 07/01/2024
1111
ms.custom: amqp, mqtt, devx-track-java, devx-track-extended-java
1212
---
1313

14-
## Upload a file from a device
14+
This how-to contains two sections:
1515

16-
Follow this procedure for uploading a file from a device to IoT Hub:
16+
* Upload a file from a device application
17+
* Receive file upload notification in a backend application
18+
19+
## Upload a file from a device application
20+
21+
Follow this procedure to upload a file from a device to IoT Hub:
1722

1823
* Connect to IoT Hub
1924
* Get a SAS URI from IoT Hub
2025
* Upload the file to Azure Storage
2126
* Send file upload status notification to IoT Hub
2227

23-
The [DeviceClient](/java/api/com.microsoft.azure.sdk.iot.device.deviceclient) class contains methods that a device can use to upload files to IoT Hub.
24-
2528
### Connection protocol
2629

27-
File upload operations always use HTTPS. `DeviceClient` can define the `IotHubClientProtocol` for other services like telemetry, device method, and device twin.
28-
29-
For example:
30+
File upload operations always use HTTPS, but [DeviceClient](/java/api/com.microsoft.azure.sdk.iot.device.deviceclient) can define the [IotHubClientProtocol](/java/api/com.microsoft.azure.sdk.iot.device.iothubclientprotocol) for other services like telemetry, device method, and device twin.
3031

3132
```java
3233
IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;
3334
```
3435

3536
### Connect to IoT Hub
3637

38+
Instantiate the DeviceClient to connect to IoT hub using the connection string and protocol parameters.
39+
3740
```java
38-
String connString = "Your device connection string here";
41+
String connString = "IoT hub connection string";
3942
DeviceClient client = new DeviceClient(connString, protocol);
4043
```
4144

@@ -45,10 +48,12 @@ Call [getFileUploadSasUri](/java/api/com.microsoft.azure.sdk.iot.device.devicecl
4548

4649
`FileUploadSasUriResponse` includes these methods and return values. The return values can be passed to file upload methods.
4750

48-
* `getCorrelationId())` - Correlation ID
49-
* `getContainerName())` - Container name
50-
* `getBlobName())` - Blob name
51-
* `getBlobUri())` - Blob URI
51+
| Method | Return value |
52+
| --------------------- | -------------- |
53+
| `getCorrelationId()` | Correlation ID |
54+
| `getContainerName()` | Container name |
55+
| `getBlobName()` | Blob name |
56+
| `getBlobUri()` | Blob URI |
5257

5358
For example:
5459

@@ -103,9 +108,9 @@ Free the `client` resources.
103108
client.closeNow();
104109
```
105110

106-
## Receive a file upload notification
111+
## Receive a file upload notification in a backend application
107112

108-
You can create an application to receive file upload notifications.
113+
You can create a backend application to receive file upload notifications.
109114

110115
The [ServiceClient](/java/api/com.azure.core.annotation.serviceclient) class contains methods that services can use to receive file upload notifications.
111116

@@ -116,7 +121,7 @@ Create a `IotHubServiceClientProtocol` object. The connection uses the `AMQPS` p
116121
Call `createFromConnectionString` to connect to IoT hub.
117122

118123
```java
119-
private static final String connectionString = "{Your service connection string here}";
124+
private static final String connectionString = "{IoT hub service connection string}";
120125
private static final IotHubServiceClientProtocol protocol = IotHubServiceClientProtocol.AMQPS;
121126
ServiceClient sc = ServiceClient.createFromConnectionString(connectionString, protocol);
122127
```

includes/iot-hub-howto-file-upload-node.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,32 @@ ms.date: 07/01/2024
1111
ms.custom: mqtt, devx-track-js
1212
---
1313

14+
This how-to contains two sections:
15+
16+
* Upload a file from a device application
17+
* Receive file upload notification in a backend application
18+
1419
## Upload a file from a device application
1520

16-
### Install the Node.js packages
21+
### Install SDK packages
1722

18-
Run these commands to install the **azure-iot-device** Device SDK, the **azure-iot-device-mqtt**, and the **@azure/storage-blob** packages: on your development machine:
23+
Run this command to install the **azure-iot-device** device SDK, the **azure-iot-device-mqtt**, and the **@azure/storage-blob** packages: on your development machine:
1924

2025
```cmd/sh
2126
npm install azure-iot-device azure-iot-device-mqtt @azure/storage-blob --save
2227
```
2328

24-
The [azure-iot-device](/javascript/api/azure-iot-device) package contains objects that interface with IoT devices. This article describes `Client` class code.
29+
The [azure-iot-device](/javascript/api/azure-iot-device) package contains objects that interface with IoT devices.
2530

26-
## Receive messages in the device application
31+
Follow this procedure for uploading a file from a device to IoT Hub:
2732

28-
This section describes how to upload a file from a device using the [azure-iot-device](/javascript/api/azure-iot-device) package in the Azure IoT SDK for Node.js.
33+
* Get Blob shared access signatures
34+
* Upload the file to Azure Storage
35+
* Send file upload status notification to IoT Hub
2936

3037
### Create modules
3138

32-
Create Client, Protocol, errors, and path modules using the packages installed in the previous step.
39+
Create Client, Protocol, errors, and path modules using the installed packages.
3340

3441
```javascript
3542
const Client = require('azure-iot-device').Client;
@@ -38,27 +45,25 @@ const errors = require('azure-iot-common').errors;
3845
const path = require('path');
3946
```
4047

41-
### Get blob shared access signatures
48+
### Get a SAS URI from IoT Hub
4249

43-
Use [getBlobSharedAccessSignature](/javascript/api/azure-iot-device/client?#azure-iot-device-client-getblobsharedaccesssignature) to get the linked storage account SAS Token from IoT Hub.
50+
Use [getBlobSharedAccessSignature](/javascript/api/azure-iot-device/client?#azure-iot-device-client-getblobsharedaccesssignature) to get the linked storage account SAS token from IoT Hub.
4451

4552
For example:
4653

4754
```javascript
4855
// make sure you set these environment variables prior to running the sample.
49-
const deviceConnectionString = process.env.DEVICE_CONNECTION_STRING;
5056
const localFilePath = process.env.PATH_TO_FILE;
5157
const storageBlobName = path.basename(localFilePath);
52-
5358
const blobInfo = await client.getBlobSharedAccessSignature(storageBlobName);
5459
if (!blobInfo) {
5560
throw new errors.ArgumentError('Invalid upload parameters');
5661
}
5762
```
5863

59-
### Upload the file to IoT Hub
64+
### Upload the file to IoT hub
6065

61-
To upload a file to IoT Hub:
66+
To upload a file to IoT hub:
6267

6368
1. Create a stream pipeline.
6469
2. Construct the blob URL.
@@ -112,13 +117,13 @@ console.log('uploadStreamToBlockBlob success');
112117
console.log(err);
113118
}
114119

115-
// Notify the blob upload status
120+
// Send file upload status notification to IoT hub
116121
await client.notifyBlobUploadStatus(blobInfo.correlationId, isSuccess, statusCode, statusDescription);
117122
```
118123

119-
## Receive a file upload notification
124+
## Receive file upload notification in a backend application
120125

121-
You can create a separate application to check the IoT Hub service client for device file upload notifications.
126+
You can create a backend application to check the IoT Hub service client for device file upload notifications.
122127

123128
### Connect to the IoT Hub service client
124129

@@ -133,7 +138,8 @@ const serviceClient = Client.fromConnectionString(connectionString);
133138
### Check for a file upload notification
134139

135140
To check for file upload notifications:
136-
* [Open](/javascript/api/azure-iothub/client?#azure-iothub-client-open-1) the connection to IoT Hub
141+
142+
* [Open](/javascript/api/azure-iothub/client?#azure-iothub-client-open-1) the connection to IoT hub.
137143
* Call [getFileNotificationReceiver](/javascript/api/azure-iothub/client?#azure-iothub-client-getfilenotificationreceiver). Supply the name of a file upload callback method that will be called when notification messages are received.
138144
* Process file upload notifications in the callback method.
139145

@@ -170,4 +176,4 @@ serviceClient.open(function (err) {
170176

171177
### Sample
172178

173-
The SDK include an [upload to blob advanced](https://github.com/Azure/azure-iot-sdk-node/blob/main/device/samples/javascript/upload_to_blob_advanced.js) sample.
179+
The SDK includes an [upload to blob advanced](https://github.com/Azure/azure-iot-sdk-node/blob/main/device/samples/javascript/upload_to_blob_advanced.js) sample.

includes/iot-hub-howto-file-upload-python.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ ms.date: 07/01/2024
1111
ms.custom: mqtt, devx-track-python, py-fresh-zinc
1212
---
1313

14-
## SDK libraries
14+
## Install device library
1515

16-
The azure-iot-device SDK library must be installed before calling any related code.
16+
The azure-iot-device library must be installed before calling any related code.
1717

1818
```cmd/sh
1919
pip install azure-iot-device
@@ -27,13 +27,13 @@ pip install azure.storage.blob
2727

2828
## Upload file from a device application
2929

30-
Follow this procedure for uploading a file from a device to IoT hub:
30+
Follow this procedure to upload a file from a device to IoT hub:
3131

3232
* Connect the client to IoT hub and get storage information
33-
* Upload the file to BloB Storage
33+
* Upload the file to Blob Storage
3434
* Notify IoT hub of upload status
3535

36-
### Import statements
36+
### Connect the client to IoT hub and get storage information
3737

3838
The [IoTHubDeviceClient](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient) class contains methods that a device can use to upload a file to IoT Hub.
3939

@@ -44,8 +44,6 @@ from azure.core.exceptions import AzureError
4444
from azure.storage.blob import BlobClient
4545
```
4646

47-
### Connect the client to IoT hub and get storage information
48-
4947
Call [create_from_connection_string](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-create-from-connection-string) to connect to IoT hub.
5048

5149
For example:
@@ -57,17 +55,13 @@ device_client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRI
5755

5856
Call [connect](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-connect) to connect the device client to an Azure IoT hub.
5957

60-
For example:
61-
6258
```python
6359
# Connect the client
6460
device_client.connect()
6561
```
6662

6763
Call [get_storage_info_for_blob](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-get-storage-info-for-blob) to get information from an IoT hub about a linked Storage Account. This information includes the hostname, container name, blob name, and a SAS token. The storage info is passed to the `store_blob` function (created in the previous step), so that 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're working on.
6864

69-
For example:
70-
7165
```python
7266
# Get the storage info for the blob
7367
PATH_TO_FILE = "[Full path to local file]"

0 commit comments

Comments
 (0)