Home > Net >  Programmatically Uploaded Azure Blob Gets Deleted
Programmatically Uploaded Azure Blob Gets Deleted

Time:12-08

I am uploading a file to Azure Blob Storage. Everything seems to work fine since I'm getting this response:

Status: 201, Value: Azure.Storage.Blobs.Models.BlobContentInfo

I can see the file in Azure Portal for about 5 seconds, then it vanishes. Any idea what may be causing this?

Here is the .Net 6 code:

using Azure.Storage.Blobs;

var input = File.Open(@"c:\temp\test.csv", FileMode.Open);
var client = new BlobServiceClient("<connection string>")
    .GetBlobContainerClient("container");
var path = "entities/1/Department/MyUpload/test.csv";
var blobClient = client.GetBlobClient(path);
var m = new Dictionary<string, string>();
m["uploadedBy"] = "user";
var response = await blobClient.UploadAsync(input, metadata: m);
Console.WriteLine(response)

One additional point: I have a blob trigger function (currently disabled) that deletes the blob after it has successfully processed it. This behavior is only happening on the path that the deleted file was on. For example, if I upload a new file in the entities/2/Department/SomeOtherUpload/someotherfile.csv path, it still gets deleted. If I upload the file on a different root path (other than entities), it works fine.

CodePudding user response:

I have a blob trigger function (currently disabled) that deletes the blob after it has successfully processed it.

Blobs will not automatically delete unless you have configured a policy or a custom operation to do this. You have clearly stated that you have this sort of logic, perhaps it is still running somewhere else? Enabling logging should help you track this down, but depending on how you have developed the function, there is a high chance it is still working either locally or in another deployment instance, even though you think it is disabled.

CodePudding user response:

You have clearly stated that you have this sort of logic, perhaps it is still running somewhere else?

Sometimes it takes a Stack Overflow post to point you to the obvious answer. I just found out that the function's build/deployment pipeline is now operational and the function is deployed in our development environment and getting triggered. I had been running the function locally and thought I had the trigger all to myself. Mystery solved!

  • Related