1

I've got a node.js service that should donwload file from azure, process it and when its done- move it to a "done" subfolder within the same container.

I've been digging in the documentation for over an hour and couldn't find any method to copy a blob or rename it, because if I create it from the beginning as done/blob-name it will visually present it inside subfolder so renaming might also do the trick (I know thats how it works and thats fine with me, I filter the blobs by ignoring all those who contains done/ in their name).

The only thing close enough is the startCopyFromURL which is a member of the "blob" class, but I can't get how to use it- because I only provide a source but no destination... all I ask is for a simple function copyBlob(sourceBlobURL, dstBlobUrl) -.-

strangely enough the Azure portal does not give any copy / renaming options, but there is something called "storage explorer" (which is accessible through azure portal) and as far as I understood it- its a GUI enabling advanced operations on blobs, including copy operations and sub-folders management. So if there's a GUI to do that, there must be a programmatic way...

im using the (kinda) new v10 sdk (here), only requiring the @azure/storage-blob part in my script.

Thanks a bunch for your help!

UPDATE: I did find references to a method called "startCopyAsync", but all examples I could find online are from sdks to different languages (c# for example) and are 1-2 years old, while the new JS sdk is officialy the primary sdk for js only since few weeks ago (july '19). Couldn't find any mention of this function in the new JS sdk.

Gibor
  • 1,695
  • 6
  • 20

2 Answers2

2

You can use startCopyFromURL, as you yourself assumed. The source is the first argument, and the target is the Blob object you use to call this method. So, the flow is something like:

  1. Create a target Blob object (empty, including all sub-folders you need, like done)
  2. Call startCopyFromURL on it providing the URL of the source
  3. Wait for promise resolution.

A non-javascript example can be found here.

Yury Fedorov
  • 14,508
  • 6
  • 50
  • 66
  • 1
    It took some time with that nasty microsoft documentation, but I finally got it. Thanks for the clarification! – Gibor Jul 24 '19 at 13:25
1

You cannot rename a blob; you can only copy a blob to a new blob (or upload a new blob).

Regarding subdirectories: there's no such thing. The hierarchy is:

account / container / blob

What looks like a subdirectory, in a blob's name, is just path characters. For example:

https://myblobs.blob.core.windows.net/mycontainer/images/image1.jpg

Is really a blob named "images/image1.jpg"

Various blob-listing calls allow you to filter using the separator character, giving the illusion of subdirectories.

So in your case, you would need to upload your "processed" blob to a new blob (whether in the same container or a new container). And if you upload to the same container, you need to come up with a new name. If you use a different container for your processed blobs, then you won't have to worry about coming up with a different blob name.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • Because of the sub-directories illusion, if I upload it to the same container under the name /done/blobName it should be fine no? – Gibor Jul 24 '19 at 09:53
  • @Gibor - correct - if you named your new `image1.jpg` something like `https://.../processed/image1.jpg` you'd be fine – David Makogon Jul 24 '19 at 10:29