Uploading a file from IOT device to Cloud in C++

SilverChips 71 Reputation points
2020-12-14T19:36:32.83+00:00

I currently have an IOT device code written in C++. I would like to upload files from the device to the cloud. I found this article which demonstrates how to achieve that in C#. I can not find anything for c++. Any suggestions on how I can upload files using a C++ client.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,157 questions
{count} votes

1 answer

Sort by: Most helpful
  1. QuantumCache 20,261 Reputation points
    2020-12-15T16:40:46.513+00:00

    Hello @ SilverChips.

    Please refer to this document Azure/azure-iot-sdk-c-->iothub_client_sample_upload_to_blob.c and azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_upload_to_blob/

        HTTP_PROXY_OPTIONS http_proxy_options = { 0 };  
            http_proxy_options.host_address = proxyHost;  
            http_proxy_options.port = proxyPort;  
      
            if (proxyHost != NULL && IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_HTTP_PROXY, &http_proxy_options) != IOTHUB_CLIENT_OK)  
            {  
                (void)printf("failure to set proxy\n");  
            }  
            else  
            {  
                if (IoTHubDeviceClient_LL_UploadToBlob(device_ll_handle, "subdir/hello_world.txt", (const unsigned char*)HELLO_WORLD, sizeof(HELLO_WORLD) - 1) != IOTHUB_CLIENT_OK)  
                {  
                    (void)printf("hello world failed to upload\n");  
                }  
                else  
                {  
                    (void)printf("hello world has been created\n");  
                }  
            }  
            // Clean up   
    

    Also refer to the official page on Device Client SDK-->Upload file to Blob

    Via HTTPS: A device can initiate a file upload and notifies IoT Hub when the upload is complete. File upload requires HTTPS connection, but can be initiated from client using any protocol for other operations.

    Please refer to this Github discussion where we get some information on uploading image files.

    How to use Blob storage from C++

    This guide demonstrates how to perform common scenarios using Azure Blob storage. The examples show how to upload, list, download, and delete blobs. The samples are written in C++ and use the Azure Storage Client Library for C++. To learn more about Blob storage, see Introduction to Azure Blob storage.

    If you ever wanted to use the Iot-edge device, then this Store data at the edge with Azure Blob Storage on IoT Edge may grab your attention.

    0 comments No comments