Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite Blob But Keep Metadata?

I need to store information on the blob (local path of the file) and to be able to overwrite that blob but keep the information.

I tried the metadata approach and its exactly what I've look for but once I overwrite the blob the metadata is also overwritten.

There is any way to overwrite a blob but keep the old metadata ?

Updating an existing block blob overwrites any existing metadata on the blob

Reference

MSDN state that there is partial update option:

To perform a partial update of the content of a block blob, use the Put Block List operation.

Put Block List

The problem is how can I set the partial update to update only the data of the blob and not the metadata ?

Thank you.

Update (further information):

I've a cloud service that get a file from the client and return a file to the client.

So what is actually happens is :

The client send request to the service to generate access to store one blob at the blob storage, the service return to him URL+SAS , I also created an actual blob with one character in order to save metadata on the blob.

The client get the URL+SAS and start upload the file using web client library.

Once the client has uploaded the file he will send request to the server with the same URL that was provided to him (and baisclly tell the service, here is my file do your thing)

The server will manipulate the file and overwrite the same blob and return a log of the whole operation.

The client can read the log and can download the "new" file from the same URL.

As you may notice the problem is that I let the client overwrite my blob, he (the client) ask me to upload file, I return him the URL+SAS but when I generated the SAS token I also created a one bit blob to holds the metadata until the user upload to the actual data, so I cant ask from the user to fetch the metadata first and then upload (I need that the upload will be from Webclient library without any special dependency like Azure API).

In conclusion

So the bottom line of the answer to my question is "No, there isn't a way to overwrite a blob and save the metadata", but Gaurav Mantri has a nice workaround to my situation.

like image 763
Ron Avatar asked May 06 '15 09:05

Ron


2 Answers

Here's one possible solution to your problem. Currently when you're creating a SAS URL, since your end user is uploading file using that it has Write permission. What you do is modify your SAS URL to include Read permission as well.

On the client application, once you receive the SAS URL first thing you would do is read the metadata of the blob using Get Blob Metadata REST API operation. You don't need to use Azure SDK for that purpose. You would do a Head request and your request URL would be https://[account].blob.core.windows.net/[container]/[blob]?sastoken&comp=metadata using WebClient only. Once you get the metadata, you can pass it back as x-ms-meta-* request headers when the user uploads the file.

like image 114
Gaurav Mantri Avatar answered Nov 16 '22 08:11

Gaurav Mantri


You can call Get Blob Metadata to fetch the metadata of existing blob at first, and then call Put Block List with the fetched metadata so that the original metadata can be kept.

like image 35
Zhaoxing Lu Avatar answered Nov 16 '22 08:11

Zhaoxing Lu