I am new to blob triggers in Azure Function apps and need a bit of help. I am struggling to find resources on how to rename the blob that triggered the function.
I have a function app that is triggered when a new blob is uploaded to a container, the file is processed and I need a way on how to 'mark' it as processed, therefore I want to rename the blob.
This is my function:
[FunctionName("ProcessFile")]
public async Task Run([BlobTrigger("storage-test-container/{name}", Connection = "BlobConnection")] Stream myBlob
, [Blob("storage-test-container/{name}", FileAccess.Write)] Stream outboundBlob, string name, ILogger log)
{
using (var reader = new StreamReader(myBlob))
{
var textAsString = await reader.ReadToEndAsync();
// Process text then rename file ...
}
}
How would I go about renaming the file? Is it even possible in this scenario?
CodePudding user response:
you can use {name} from the trigger path.
Console.WriteLine("This is the filename: " name);
CodePudding user response:
How would I go about renaming the file?
Considering renaming a blob is not natively supported, what you will need to do is copy the source blob with a different name and then delete it. That is equivalent of renaming a blob.
Is it even possible in this scenario?
Even though it is technically possible to do so, I would not recommend it. When you copy the blob, a new blob will be created and that would fire your Function again. Thus you would end up in an infinite loop.
A better approach would be to create a separate blob container (e.g. storage-test-container-processed
) and then copy the source blob to this container and delete it once the blob is copied successfully. Essentially you will be moving a blob instead of renaming it.