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
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 from a device to Blob Storage.
41
+
Call [GetFileUploadSasUriAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.getfileuploadsasuriasync) to get a file upload details. The SAS URI is used in the next step to upload a file from a device to Blob Storage.
Create a [blockBlobClient](/dotnet/api/azure.storage.blobs.specialized.blockblobclient) object, passing a file upload URI.
58
+
To upload a file to Azure storage:
59
59
60
-
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.
60
+
* Create a [blockBlobClient](/dotnet/api/azure.storage.blobs.specialized.blockblobclient) object, passing a file upload URI
61
+
62
+
* 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
61
63
62
64
The Azure Blob client always uses HTTPS as the protocol to upload the file to Azure Storage.
63
65
64
-
In this example, `BlockBlobClient` is passed the SAS URI to create an Azure Storage block blob client and uploads the file:
66
+
In this example, `BlockBlobClient` is passed the SAS URI to create an Azure Storage block Blob client and uploads the file:
Use [CompleteFileUploadAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.completefileuploadasync) to notify IoT Hub that the device client completed the upload. After being notified, IoT Hub will release resources associated with the upload (the SAS URI).
75
+
Use [CompleteFileUploadAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.completefileuploadasync) to notify IoT Hub that the device client completed the upload, passing a [FileUploadCompletionNotification](/dotnet/api/microsoft.azure.devices.client.transport.fileuploadcompletionnotification) object. The `IsSuccess` flag indicates whether or not the upload was successful. After being notified, IoT Hub will release resources associated with the upload (the SAS URI).
74
76
75
-
If file upload notifications are enabled, IoT Hub sends a notification message to backend services.
77
+
If file upload notifications are enabled, IoT Hub sends a file upload notification message to backend services that are configured for file upload notification.
### Receive file upload notification in a backend application
112
-
113
-
You can create a separate backend application to receive file upload notifications.
114
-
115
-
The [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient) class contains methods that services can use to receive file upload notification.
102
+
The [ServiceClient](/dotnet/api/microsoft.azure.devices.serviceclient) class contains methods that services can use to receive file upload notifications.
116
103
117
104
To receive file upload notification:
118
105
@@ -121,12 +108,20 @@ To receive file upload notification:
121
108
* Use a loop with [ReceiveAsync](/dotnet/api/microsoft.azure.devices.receiver-1.receiveasync?#microsoft-azure-devices-receiver-1-receiveasync(system-threading-cancellationtoken)) to wait for the file upload notification.
Pass the blob URI endpoint to [BlobClientBuilder](/java/api/com.azure.storage.blob.blobclientbuilder?#com-azure-storage-blob-blobclientbuilder-buildclient()) to create the [BlobClient](/java/api/com.azure.storage.blob.blobclient) object.
74
+
Pass the blob URI endpoint to [BlobClientBuilder.buildclient](/java/api/com.azure.storage.blob.blobclientbuilder?#com-azure-storage-blob-blobclientbuilder-buildclient()) to create the [BlobClient](/java/api/com.azure.storage.blob.blobclient) object.
* Create a [getFileUploadNotificationReceiver](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotificationreceiver) object.
134
136
* Use [open](/java/api/com.microsoft.azure.sdk.iot.service.fileuploadnotificationreceiver?#com-microsoft-azure-sdk-iot-service-fileuploadnotificationreceiver-open()) to connect to IoT Hub.
135
137
* 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) 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.
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-file-upload-node.md
+25-24Lines changed: 25 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,51 +129,52 @@ You can create a backend application to check the IoT Hub service client for dev
129
129
130
130
### Connect to the IoT Hub service client
131
131
132
-
Create the [Client](/javascript/api/azure-iothub/client) using [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring).
132
+
Create the [ServiceClient](/javascript/api/azure-iothub/client) using [fromConnectionString](/javascript/api/azure-iothub/client?#azure-iothub-client-fromconnectionstring).
[Open](/javascript/api/azure-iothub/client?#azure-iothub-client-open-1) the connection to IoT hub.
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
+
```
150
+
140
151
### Check for a file upload notification
141
152
142
153
To check for file upload notifications:
143
154
144
-
*[Open](/javascript/api/azure-iothub/client?#azure-iothub-client-open-1) the connection to IoT hub.
145
155
* 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.
146
156
* Process file upload notifications in the callback method.
147
157
148
158
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.
149
159
150
160
```javascript
151
-
//Open the connection to IoT hub
152
-
serviceClient.open(function (err) {
153
-
if (err) {
154
-
console.error('Could not connect: '+err.message);
155
-
} else {
156
-
console.log('Service client connected');
157
-
//Set up the receiveFileUploadNotification notification message callback receiver
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-file-upload-python.md
+34-72Lines changed: 34 additions & 72 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ Follow this procedure to upload a file from a device to IoT hub:
34
34
* Upload the file to Blob Storage
35
35
* Notify IoT hub of upload status
36
36
37
-
### Connect to IoT hub
37
+
### Import libraries
38
38
39
39
```python
40
40
import os
@@ -43,31 +43,30 @@ from azure.core.exceptions import AzureError
43
43
from azure.storage.blob import BlobClient
44
44
```
45
45
46
-
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.
46
+
### Connect to IoT hub
47
+
48
+
Call [create_from_connection_string](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-create-from-connection-string) to add the connection string. Then 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.
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.
56
56
57
-
```python
58
57
# Connect the client
59
58
device_client.connect()
60
59
```
61
60
62
61
### Get Blob Storage information
63
62
64
-
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.
63
+
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 Azure Storage account. This information includes the hostname, container name, blob name, and a SAS token. 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.
@@ -77,41 +76,40 @@ To upload a file into Blob Storage:
77
76
* Use [from_blob_url](/python/api/azure-storage-blob/azure.storage.blob.blobclient?#azure-storage-blob-blobclient-from-blob-url) to create a [BlobClient](/python/api/azure-storage-blob/azure.storage.blob.blobclient?#azure-storage-blob-blobclient-from-blob-url) object from a blob URL.
78
77
* Call [upload_blob](/python/api/azure-storage-blob/azure.storage.blob.blobclient?#azure-storage-blob-blobclient-upload-blob) to upload the file into the Blob Storage.
79
78
80
-
This example function parses the passed`blob_info` structure to create a URL that it uses to initialize an [BlobClient](/python/api/azure-storage-blob/azure.storage.blob.blobclient). Then it calls `upload_blob` to upload the file into Blob Storage.
79
+
This example parses the `blob_info` structure to create a URL that it uses to initialize an [BlobClient](/python/api/azure-storage-blob/azure.storage.blob.blobclient). Then it calls `upload_blob` to upload the file into Blob Storage.
81
80
82
81
```python
83
-
defstore_blob(blob_info, file_name):
84
-
try:
85
-
sas_url ="https://{}/{}/{}{}".format(
86
-
blob_info["hostName"],
87
-
blob_info["containerName"],
88
-
blob_info["blobName"],
89
-
blob_info["sasToken"]
90
-
)
91
-
92
-
print("\nUploading file: {} to Azure Storage as blob: {} in container {}\n".format(file_name, blob_info["blobName"], blob_info["containerName"]))
93
-
94
-
# Upload the specified file
95
-
with BlobClient.from_blob_url(sas_url) as blob_client:
96
-
withopen(file_name, "rb") as f:
97
-
result = blob_client.upload_blob(f, overwrite=True)
98
-
return (True, result)
99
-
100
-
exceptFileNotFoundErroras ex:
101
-
# catch file not found and add an HTTP status code to return in notification to IoT Hub
102
-
ex.status_code =404
103
-
return (False, ex)
104
-
105
-
except AzureError as ex:
106
-
# catch Azure errors that might result from the upload operation
107
-
return (False, ex)
82
+
try:
83
+
sas_url ="https://{}/{}/{}{}".format(
84
+
blob_info["hostName"],
85
+
blob_info["containerName"],
86
+
blob_info["blobName"],
87
+
blob_info["sasToken"]
88
+
)
89
+
90
+
print("\nUploading file: {} to Azure Storage as blob: {} in container {}\n".format(file_name, blob_info["blobName"], blob_info["containerName"]))
91
+
92
+
# Upload the specified file
93
+
with BlobClient.from_blob_url(sas_url) as blob_client:
94
+
withopen(file_name, "rb") as f:
95
+
result = blob_client.upload_blob(f, overwrite=True)
96
+
return (True, result)
97
+
98
+
exceptFileNotFoundErroras ex:
99
+
# catch file not found and add an HTTP status code to return in notification to IoT Hub
100
+
ex.status_code =404
101
+
return (False, ex)
102
+
103
+
except AzureError as ex:
104
+
# catch Azure errors that might result from the upload operation
105
+
return (False, ex)
108
106
```
109
107
110
108
### Notify IoT hub of upload status
111
109
112
110
Use [notify_blob_upload_status](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-notify-blob-upload-status) to notify IoT hub of the status of the Blob Storage operation. Pass the `correlation_id` obtained by the `get_storage_info_for_blob` method. The `correlation_id` is used by IoT Hub to notify any service that might be listening for a notification regarding the status of the file upload task.
113
111
114
-
For example:
112
+
This example notifies IoT hub of a successful file upload:
0 commit comments