Skip to content

Commit 4f89fb9

Browse files
committed
Added content
1 parent cb0008e commit 4f89fb9

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ ServiceClient sc = ServiceClient.createFromConnectionString(connectionString, pr
123123

124124
### Check for file upload status
125125

126+
* Create a [getFileUploadNotificationReceiver](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotificationreceiver) object.
127+
* Use [open](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotificationreceiver?#com-microsoft-azure-sdk-iot-service-fileuploadnotificationreceiver-open()) to connect to IoT Hub.
128+
* Call [receive](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotificationreceiver?#com-microsoft-azure-sdk-iot-service-fileuploadnotificationreceiver-receive()) to check for the file upload status. This method returns a [fileUploadNotification](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotification?view=azure-java-stable) object. If an upload notice is received, you can view upload status fields using [fileUploadNotification](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotification) methods.
129+
130+
For example:
131+
126132
```java
127133
FileUploadNotificationReceiver receiver = sc.getFileUploadNotificationReceiver();
128134
receiver.open();

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const path = require('path');
4242

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

45+
For example:
46+
4547
```javascript
4648
// make sure you set these environment variables prior to running the sample.
4749
const deviceConnectionString = process.env.DEVICE_CONNECTION_STRING;
@@ -58,7 +60,7 @@ throw new errors.ArgumentError('Invalid upload parameters');
5860

5961
To upload a file to IoT Hub:
6062

61-
1. Creates a communication pipeline.
63+
1. Create a stream pipeline.
6264
2. Constructs the blob URL.
6365
3. Create a [BlockBlobClient](/javascript/api/@azure/storage-blob/blockblobclient) for file upload to Blob Storage.
6466
4. Call [uploadFile](/javascript/api/@azure/storage-blob/blockblobclient?#@azure-storage-blob-blockblobclient-uploadfile) to upload the file to Blob Storage.
@@ -112,7 +114,58 @@ console.log('uploadStreamToBlockBlob success');
112114

113115
// Notify the blob upload status
114116
await client.notifyBlobUploadStatus(blobInfo.correlationId, isSuccess, statusCode, statusDescription);
117+
```
118+
119+
## Receive a file upload notification
120+
121+
You can create a separate application to check the IoT Hub service client for device file upload notifications.
122+
123+
### Connect to the IoT Hub service client
124+
125+
Create the [Client](/javascript/api/azure-iothub/client) using [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring).
126+
127+
```javascript
128+
const Client = require('azure-iothub').Client;
129+
const connectionString = "{IoT hub connection string}";
130+
const serviceClient = Client.fromConnectionString(connectionString);
131+
```
132+
133+
### Check for a file upload notification
134+
135+
To check for file upload notifications:
136+
* [Open](/javascript/api/azure-iothub/client?view=azure-node-latest#azure-iothub-client-open-1) the connection to IoT Hub
137+
* 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.
138+
* Process file upload notifications in the callback method.
115139

140+
This example sets up a `receiveFileUploadNotification` notification callback receiver. The receiver interprets the file upload status information and prints a status messsage to the console.
141+
142+
```javascript
143+
//Open the connection to IoT hub
144+
serviceClient.open(function (err) {
145+
if (err) {
146+
console.error('Could not connect: ' + err.message);
147+
} else {
148+
console.log('Service client connected');
149+
//Set up the receiveFileUploadNotification notification message callback receiver
150+
serviceClient.getFileNotificationReceiver(function receiveFileUploadNotification(err, receiver){
151+
if (err) {
152+
console.error('error getting the file notification receiver: ' + err.toString());
153+
} else {
154+
receiver.on('message', function (msg) {
155+
console.log('File upload from device:')
156+
console.log(msg.getData().toString('utf-8'));
157+
receiver.complete(msg, function (err) {
158+
if (err) {
159+
console.error('Could not finish the upload: ' + err.message);
160+
} else {
161+
console.log('Upload complete');
162+
}
163+
});
164+
});
165+
}
166+
});
167+
}
168+
});
116169
```
117170

118171
### Sample

0 commit comments

Comments
 (0)