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:
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