Take the 2-minute tour ×

i am able to upload file to azure blob using REST api provided by Azure.

i want to set metadata at the time i am doing request for put blob, when i am setting it into header as shown here i am unble to upload file and getting following exception org.apache.http.client.ClientProtocolException.

from the last line of the code below

    HttpPut req = new HttpPut(uri);
    req.setHeader("x-ms-blob-type", blobType);
    req.setHeader("x-ms-date", date);
    req.setHeader("x-ms-version", storageServiceVersion);
    req.setHeader("x-ms-meta-Cat", user);
    req.setHeader("Authorization", authorizationHeader);

    HttpEntity entity = new InputStreamEntity(is,blobLength);

    HttpResponse response = httpClient.execute(req);

regarding the same, i have two questions.

  1. can setting different metadata, avoid overwriting of file? See my question for the same here

  2. if Yes for first question, how to set metadata in REST request to put blob into Azure?

please help

share|improve this question
Can you share the code for generating authorization header? One thing you may want to ensure is that you're including custom metedata headers also in your autorization header calculation. Also you may want to trace the request/response in Fiddler to see the exact error message returned by storage service. –  Gaurav Mantri Jun 6 '13 at 12:31
techblogvjd.blogspot.in/2013/06/virustechblog1.html this is the same thing what i have done, just single change, used inputstream instead of file –  VD' Jun 6 '13 at 13:08
add comment

1 Answer

So a few things are going here.

Regarding the error you're getting, it is because you're not adding your metadata header when calculating authorization header. Please read Constructing the Canonicalized Headers String section here: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx.

Based on this, you would need to change the following line of code (from your blog post)

String canonicalizedHeaders = "x-ms-blob-type:"+blobType+"\nx-ms-date:"+date+"\nx-ms-version:"+storageServiceVersion;


String canonicalizedHeaders = "x-ms-blob-type:"+blobType+"\nx-ms-date:"+date+"\nx-ms-meta-cat"+user+"\nx-ms-version:"+storageServiceVersion;

(Note: I have just made these changes in Notepad so they may not work. Please go to the link I mentioned above for correctly creating the canonicalized headers string.

can setting different metadata, avoid overwriting of file?

Not sure what you mean by this. You can update metadata of a blob by performing Set Blob Metadata operation on a blog.

share|improve this answer
i have done this, this is still giving the same exception :( –  VD' Jun 7 '13 at 6:27
It would help if you paste the entire code. Also try to trace your request through Fiddler so that you know the exact error sent by storage service. –  Gaurav Mantri Jun 7 '13 at 8:29
add comment

Your Answer


