Share via

Azure Function Destination Connection Definition

Ankit Kumar 91 Reputation points
2020-10-13T10:15:39.62+00:00

So I have two questions here which I am trying to achieve using C# in Azure Functions:

I am suppose to copy blobs from one container to another in same storage account whenever a new blob or directory arrives in the source container. the new blob in destination should have a different name.

I started with my code in Visual Studio using Azure function SDK and I have come up till here:

namespace CopyBlobs
{
    public static class CopyBlob
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("SourceContainerName/{name}", Connection = "AzureWebJobsStorage")]CloudBlockBlob myBlob, IDictionary<string, string> metadata, string name, ILogger log)



        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n ContentMD5: {myBlob.Properties.ContentMD5} \n Size: {myBlob.Properties.Length}");
            log.LogInformation($"metadata count {metadata.Count}");
            {
                var destinationContainer = myBlob.Container.ServiceClient.GetContainerReference(metadata["Destination"]);
                destinationContainer.CreateIfNotExistsAsync();                
                CloudBlockBlob outputBlob = destinationContainer.GetBlockBlobReference(name);           
                outputBlob.StartCopyAsync(myBlob);
            }
        }
    }
}

Q1) I get the error on line var destinationContainer = myBl... as Destination key is not defined. I would like to know where and what to define in the Destination key and if anyone can show me an example (I believe it should be my destination container name in localsetting.json file but I am struggling to define it correctly).

Q2) The destination blob which is copied should have a different name, it will be something like the original name manipulated to base64. How can I achieve that?

I am new to do this Azure function thing so i am going slow but hoping to get some quick help here.

Thanks

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


Answer accepted by question author

Pramod Valavala 20,661 Reputation points Microsoft Employee Moderator
2020-10-14T05:54:17.677+00:00

For Q1, the metadata property is a dictionary of user defined properties for the blob. Could you confirm if you are setting this when creating the blob?

For Q2, you could just encode name to base64 using methods shared in this SO thread.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

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.