How to solve 'CloudBlockBlob' does not contain a definition for 'UploadFromStream'?

DataSciencentist2021 141 Reputation points
2022-01-10T10:33:05.933+00:00

Hi everyone,

Using Visual Studio Code I am currently trying to create a function which receives data from a Modbus-TCP module and stores it in block blobs.

Yet, I haven't really figured out how to access the data routed from the Modbus-module to my custom module.

My code is based on the offical sql-server-tutorial (https://learn.microsoft.com/en-us/azure/iot-edge/tutorial-store-data-sql-server?view=iotedge-2020-11) and the blob-storage-tutorial from Sander van de Velde (https://sandervandevelde.wordpress.com/2018/11/04/introducing-blob-storage-in-azure-iot-on-the-edge/).

Unfortunately when I try to "Build and Push the IoT Edge Solution" and Error occurs:

#12 2.407 streamToBlob.cs(46,18): error CS1061: 'CloudBlockBlob' does not contain a definition for 'UploadFromStream' and no accessible extension method 'UploadFromStream' accepting a first argument of type 'CloudBlockBlob' could be found (are you missing a using directive or an assembly reference?) [/app/streamToBlob.csproj]  

I double checked and Microsoft says that 'UploadFromStream' is contained in 'CloudBlockBlob'. (https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.storage.blob.cloudblockblob.uploadfromstreamasync?view=azure-dotnet-legacy)

Sander van de Velde uses "Microsoft.WindowsAzure.Storage.Blob" in his code, but I can't find it when trying to add this package to my code via Nuget. The only packages I find are the following:

163449-packages-available.png

So I chose "Microsoft.Azure.Storage.Blob", but this did not solve the problem.

Here is the code I try to use without the account credentials:

using Microsoft.WindowsAzure.Storage;  
using Microsoft.Azure.Storage.Blob;  
using System;  
using System.IO;  
using System.Text;  
using System.Threading.Tasks;  
using Microsoft.Azure.Devices.Client;  
using Microsoft.Azure.WebJobs;  
using Microsoft.Azure.WebJobs.Extensions.EdgeHub;  
using Microsoft.Azure.WebJobs.Host;  
using Microsoft.Extensions.Logging;  
using Newtonsoft.Json;  
  
namespace Functions.Samples  
{  
    public static class streamToBlob  
    {  
        [FunctionName("streamToBlob")]  
        public static async Task getMessageAndStream(  
            [EdgeHubTrigger("input1")] Message messageReceived,  
            ILogger logger)  
        {  
            logger.LogInformation("Info: message received" + messageReceived);  
  
            // Blob container construction  
            var account = CloudStorageAccount.Parse(  
        "DefaultEndpointsProtocol=https;BlobEndpoint=http://<IP-address>:11002/<LOCAL BLOB STORAGE ACCOUNT>;AccountName=<LOCAL BLOB STORAGE ACCOUNT>;AccountKey=<LOCAL BLOB STORAGE KEY>");  
  
            var client = account.CreateCloudBlobClient();  
  
            // creates a local CloudBlobContainer object  
            var container = client.GetContainerReference("<LOCAL BLOB CONTAINER NAME>");  
  
            var now = DateTime.Now;  
  
            var filename = "Datei_" + now.ToString("dd-MM-yyyy, HH:mm:ss");  
  
            var blob = container.GetBlockBlobReference(filename);  
  
            blob.UploadFromStream(messageReceived);  
  
            // Do we already have a blob?  
            var exists = blob.ExistsAsync().Result;  
  
            if (!exists)  
            {  
                await blob.UploadTextAsync($"Written text at {DateTime.Now.ToLocalTime()}");  
                logger.LogInformation("Info: Blob was uploaded");  
            }  
            else  
            {  
                await blob.UploadTextAsync($"Blob is already existing!");  
                logger.LogInformation("Info: Blob is already existing!");  
            }  
        }  
    }  
}  
  
  

Any ideas regarding this?

Best regards

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Sander van de Velde | MVP 36,951 Reputation points MVP Volunteer Moderator
    2022-01-11T13:01:26.89+00:00

    Hello @DataSciencentist2021 , @Anonymous ,

    yes, this blog post is more than three years old so the specific tooling somewhat is deprecated.

    The solution is still valid so please refer to the new Nuget packages.

    Please check out:

    <PackageReference Include="Azure.Storage.Blobs" Version="12.8.3" />  
    

    This is taken from a recent project where the same blob storage on the edge was used.

    As seen here, v1.4.1 supports Azure.Storage.Blobs 12.8.0 SDK.


1 additional answer

Sort by: Most helpful
  1. Anonymous
    2022-01-10T20:55:20.273+00:00

    @DataSciencentist2021
    Microsoft.Azure.Storage.Blob and Microsoft.WindowsAzure.Storage.Blob are both legacy and you should consider using the latest SDK which is Azure.Storage.Blobs. Please see this StackOverflow post which gives good detail on the differences and suggestions on upgrading.
    You might consider adding Microsoft.Azure.Storage to see if that resolves your issue. Though we recommend upgrading to the latest SDK. Quickstart and samples can be found on this page.

    Hope this helps. Let us know if you run into any issues or need further assistance.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.