public async Task RunAsync(
[BlobTrigger("test/{name}", Connection = "CONN")]Stream incommingBlob,
string name, ILogger log,
[Blob("test/{name}", FileAccess.Read, Connection = "CONN")] CloudBlockBlob insertBlob,
CancellationToken token)
{
var inputFileUrl = insertBlob?.Container.GetBlockBlobReference(name).Uri.AbsoluteUri;
var platformApiStatus = await _UpdateService.UploadFile(name, inputFileUrl, token);
log.LogInformation($"Upload file functionality invoked returned status:{platformApiStatus} for the file {name} and blob {incommingBlob}");
}
Exception :
Microsoft.Azure.WebJobs.Host: Error indexing method 'UpdateFunction'. Microsoft.Azure.WebJobs.Host: Can't bind Blob to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob'.
As mentioned in the comments, CloudBlockBlob
is only supported with deprecated package Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
, you have to use BlockBlobClient
or BlobClient
instead which is supported with Azure.Storage.Blob
Package.
Below is the simple example for BlobClient
.
This code reads file and converts the content to Uppercase and uploads the file to the Container.
Reading the contents from test
container and uploading the modified file to uploadfile
container.
Code Snippet:
using Azure.Storage.Blobs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
public class BlobUploadFunction
{
[FunctionName("BlobTrigger")]
public static async Task Run(
[BlobTrigger("test/{name}", Connection = "demo")] Stream inputBlob,
string name,
[Blob("uploadfile/{name}", FileAccess.Write, Connection = "demo")] BlobClient outputBlob,
ILogger log)
{
log.LogInformation($"Processing text blob: {name}, Size: {inputBlob.Length} Bytes");
using var reader = new StreamReader(inputBlob);
string content = await reader.ReadToEndAsync();
string modifiedContent = content.ToUpperInvariant();
using var outputStream = new MemoryStream(Encoding.UTF8.GetBytes(modifiedContent));
var res= await outputBlob.UploadAsync(outputStream, overwrite: true);
log.LogInformation($"Processed text blob '{name}' and uploaded modified content.");
}
}
.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.10.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.24.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.22.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.22.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.3.4" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.11.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Output:
Functions:
BlobTrigger: blobTrigger
For detailed output, run func with --verbose flag.
[2025-05-23T10:55:58.163Z] Host lock lease acquired by instance ID '0000000000000000000000004F4DDDC0'.
[2025-05-23T10:56:35.965Z] Executing 'BlobTrigger' (Reason='New blob detected(LogsAndContainerScan): test/HelloWorld.txt', Id=631a00a4-89aa-432b-9a5a-0bb3c2ee45be)
[2025-05-23T10:56:35.973Z] Trigger Details: MessageId: 8697de12-ef04-48b9-90c7-a0aec9c640af, DequeueCount: 1, InsertedOn: 2025-05-23T10:56:34.000+00:00, BlobCreated: 2025-05-23T10:54:12.000+00:00, BlobLastModified: 2025-05-23T10:56:37.000+00:00
[2025-05-23T10:56:36.012Z] Processing text blob: HelloWorld.txt, Size: 50 Bytes
[2025-05-23T10:56:36.543Z] Processed text blob 'HelloWorld.txt' and uploaded modified content.
[2025-05-23T10:56:36.579Z] Executed 'BlobTrigger' (Succeeded, Id=631a00a4-89aa-432b-9a5a-0bb3c2ee45be, Duration=1545ms)
File Content in test
container:
Modified File content in uploadfile
container: