5

I've got a text file I need to append data to daily with a timer Azure Function. The text file is a comma separated file. I've created my CloudBlobClient and knew how to make my Shared Access Policy and Token. I just don't know how to use this to upload. I only know how to get an access URI from the tutorial I'm working with.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
A.Rowan
  • 1,460
  • 2
  • 16
  • 20

1 Answers1

8

I've got a text file I need to append data to daily with a timer Azure Function.

You can try to use append blob that is optimized for append operations. According to your description, you know how to get SAS URI, so you can use SAS URI to create a reference to an append blob, and append a file to an append blob, the following code is for your reference.

CloudAppendBlob appendBlob = new CloudAppendBlob(new Uri("https://{storage_account}.blob.core.windows.net/{your_container}/append-blob.log?st=2017-09-25T02%3A10%3A00Z&se=2017-09-27T02%3A10%3A00Z&sp=rwl&sv=2015-04-05&sr=b&sig=d0MENO44GjtBLf7L8U%2B%2F2nGwPAayjiVSSHaKJgEkmIs%3D"));


appendBlob.AppendFromFile("{filepath}\source.txt");
Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • 5
    Be advised BlockBlobs cannot be accessed as AppendBlobs. The file needs to be created as an AppendBlob for this to work. Your use case does call for an AppendBlob, so I would advise to create the blob as an AppendBlob :) – rickvdbosch Sep 26 '17 at 07:07
  • 1
    Yes, the file needs to be created as an append blob. – Fei Han Sep 26 '17 at 07:11
  • 1
    Append blob. Append blob. Append blob. – Beakie Apr 08 '19 at 13:03
  • Should this code run? Struggling for hours with it. The AccountKey seems to be missing. And there is a lot of 'garbage' after the file name. Can I remove that? – Yster Nov 06 '20 at 23:57