Azure IoT Upload Files

Azure IoT allows to send data using several protocols like MQTT or AMQP, but in some cases, the size of the message is too big and requires to upload files to Azure Servers. To provide a solution to this issue IoT hub facilitates file uploads from connected devices by providing them with shared access signature (SAS) URIs on a per-upload basis for a blob container and Azure storage account that have been pre-configured with the hub. 

From sgcWebSockets 2023.8.0, you can upload files using Azure IoT client. Certificates and SAS are both authentication methods supported.

You can read more about File Upload using the following link:

https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-file-upload

Upload File Using Certificates

First configure the certificates in your Azure Account and then set the paths of the certificate and key file in the Azure IoT Client Component. Call the method UploadFile to upload a file from a filename path.

oClient := TsgcIoTAzure_MQTT_Client.Create(nil);
Try
  oClient.Certificate.CertFile := 'cert.pem';
  oClient.Certificate.KeyFile := 'key.pem';
  oClient.Certificate.Enabled := True;
  oDialog := TOpenDialog.Create(nil);
  Try
    if oDialog.Execute then
      oClient.UploadFile(oDialog.FileName);
  Finally
    oDialog.Free;
  End;
Finally
  FreeAndNil(oClient);
End; 

Upload File Using SAS

First configure the Secret Key in the Azure IoT Client Component. Call the method UploadFile to upload a file from a filename path.

oClient := TsgcIoTAzure_MQTT_Client.Create(nil);
Try
  oClient.SAS.SecretKey := 'your-secret-key';
  oClient.SAS.KeyName := 'key-name';
  oClient.SAS.Enabled := True;
  oDialog := TOpenDialog.Create(nil);
  Try
    if oDialog.Execute then
      oClient.UploadFile(oDialog.FileName);
  Finally
    oDialog.Free;
  End;
Finally
  FreeAndNil(oClient);
End; 

sgcWebSockets IoT Amazon and Azure Client Demo

Compiled demo for windows showing the main features of Amazon and Azure IoT APIs
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Delphi Indy Server EC Certificates
sgcWebSockets 2023.7

Related Posts