×
Namespaces

Variants
Actions

Talk:Azure Blob Storage - Uploading images using REST API

From Nokia Developer Wiki
Jump to: navigation, search

Contents

Hamishwillee - Subedited/Reviewed

Great job - completely clear to me, and I can see this would have been tough to work out from scratch. Also thanks for sticking to wiki style - no br's :-)

I've subedited for English and readability. I think you'll like it - nothing massive, just makes the explanation a bit easier to follow.

Also changed the title - for consistency. Note also the new categories.

Regards

Hamish

hamishwillee 08:31, 28 June 2013 (EEST)

Mfabiop - Images in english

Hi galazzo,

Very interest article!

I think that would be better to change the images to english version, as we have some no-latin readers (chinese, arabian, etc) here.

Br,

Anyway, great article! I come to see it as soon as I read the title! :) Congrats!

mfabiop 14:47, 28 June 2013 (EEST)

Galazzo -

Hi Mfabiop

yes you are right and I know and understand that images in italian could be a problem for some people, of course due to my italian settings. I preferred first to write the article as now I can and plan to update as soon as I can.

Thanks, for your appreciations, so stay tuned as I'm working on other articles focuesd on Azure cloud services.

Best regards,

Sebastiano

galazzo 15:33, 28 June 2013 (EEST)

Hamishwillee - And of course anyone else can too

So if anyone reading this is trying it out with English settings, please feel free to upload the English image version.

hamishwillee 04:54, 3 July 2013 (EEST)

Mfabiop -

Hi Hamish

I've tried to access the https://manage.windowsazure.com site, but i only receive a "No Subscription" message. So, i'm not able to get the screens in english language. I guess that i should have some 'special' account to do that.

Br,

mfabiop 05:11, 3 July 2013 (EEST)

Galazzo -

Hi Mfabiop

of course you need to subscribe to the service and I had no problems and used the same Microsoft account created to publish my applications. Try thi link: https://account.windowsazure.com/Home/Index

Br,

Sebastiano

galazzo (talk) 11:31, 4 July 2013 (EEST)

Java UserA - Set Blob properties - authentication error

Hi,

I am using the following put request in java and i am getting "Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature."

PUT https://acptest2.blob.core.windows.net/?restype=service&comp=properties HTTP/1.1 [x-ms-date: Tue, 13 Aug 2013 13:27:16 GMT, x-ms-version: 2011-08-18, Authorization: SharedKey acptest2:X8WaQrrf4LToOnrxnepdDTg9YCGurJtR1HcCaV4i1Cc=, Host: acptest2.blob.core.windows.net]

body: <?xml version="1.0" encoding="UTF-8"?> <StorageServiceProperties><Logging><Version>1.0</Version><Delete>true</Delete><Read>true</Read><Write>true</Write><RetentionPolicy><Enabled>true</Enabled><Days>7</Days></RetentionPolicy></Logging><Metrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>false</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>1</Days></RetentionPolicy></Metrics></StorageServiceProperties>

Response i am getting:


   <?xml version="1.0" encoding="utf-8"?>
   <Error>
AuthenticationFailed
   <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
   RequestId:4a2103e3-162a-457e-9d36-3430816f30e7
   Time:2013-08-13T13:29:03.4641809Z</Message>
   <AuthenticationErrorDetail>Request date header too old: 'Tue, 13 Aug 2013 01:16:31 GMT'</AuthenticationErrorDetail>
   </Error>

help/advice with sample code in java as given above for blob upload or delete blob will be really helpful. Thanks in advance,

Anite

Java_UserA (talk) 16:32, 13 August 2013 (EEST)

Galazzo -

Hi Anite,

Sorry nut I'm not a Java expert so I can't help you with the language but at a first glance it seams the date is wrong. Please be sure is in the correct format. May be this link can help you: http://msdn.microsoft.com/en-us/library/dd135714.aspx

Please let me know if you solve. I'm available if you still need help.

Sebastiano

galazzo (talk) 16:37, 13 August 2013 (EEST)

Java UserA - set blob service properties

Hi Sebastiano, I have corrected date error, now i am getting the following response. Please help to understand the error.

   <?xml version="1.0" encoding="utf-8"?>
   <Error>
AuthenticationFailed
   <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
   RequestId:4d3b3fb4-cec0-45e6-bb7a-ac1f0ab4f241
   Time:2013-08-14T11:06:46.0788836Z</Message>
   <AuthenticationErrorDetail>The MAC signature found in the HTTP request 'olsO0nz+DmduvfvoW6q6afPIfj4K3fACtoXqK77Hjag=' is not the same as any computed signature. Server used following string to sign: 'PUT
    
    
   375
    
   text/plain; charset=UTF-8
    
    
    
    
    
    
   x-ms-date:Wed, 14 Aug 2013 11:03:04 GMT
   x-ms-version:2011-08-18
   /acptest2/
   comp:properties
   restype:service'.</AuthenticationErrorDetail>
</Error>

Java_UserA (talk) 14:14, 14 August 2013 (EEST)

Galazzo -

Hi Anite,

Not sure without reading the full code but check if you are using the correct key you have to get in the Management Portal. Do not use the master key ( the second ) but the first one.

This is what I can suggest with these infornations.

I'm also away now so could help you better when I come back. Let me know.

Sebastiano

galazzo (talk) 14:24, 14 August 2013 (EEST)

Java UserA - set blob properties

hi Sebastiano,

Please find below my code for setting blob properties, help me to solve the error.

Thanks, Anite


public static String signRequest(URL url, String account, String key) throws Exception {

StringBuilder sb = new StringBuilder(); sb.append("PUT\n"); // method sb.append('\n'); // content encoding sb.append('\n'); // content language sb.append("433\n"); // content length sb.append('\n'); // md5 (optional) sb.append("text/xml\n"); // content type sb.append('\n'); // legacy date sb.append('\n'); // if-modified-since sb.append('\n'); // if-match sb.append('\n'); // if-none-match sb.append('\n'); // if-unmodified-since sb.append('\n'); // range sb.append("x-ms-date:" + getDate() + '\n'); // headers sb.append("x-ms-version:2011-08-18\n");

String canonicalizedResource = getCanonicalizedResource(url, account);

sb.append(canonicalizedResource);

Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(base64.decode(key), "HmacSHA256")); String authKey = new String(base64.encode(mac.doFinal(sb.toString().getBytes("UTF-8")))); String auth = "SharedKey " + account + ":" + authKey;

return auth; }

public static void setServiceProperties(String Url, String key) throws Exception{

String spUrl = Url + "?restype=service&comp=properties";

HttpClient client = new DefaultHttpClient();

StorageServiceProperties storageServiceProperties = new StorageServiceProperties(); Logging logging = new Logging(); logging.setVersion(1); logging.setDelete(true); logging.setRead(true); logging.setWrite(true);

RetentionPolicy retentionPolicy = new RetentionPolicy(); retentionPolicy.setEnabled(true); retentionPolicy.setDays(new BigInteger("7"));

logging.setRetentionPolicy(retentionPolicy); storageServiceProperties.setLogging(logging);

Metrics metrics = new Metrics(); metrics.setEnabled(false); //metrics.setIncludeAPIs(false);

RetentionPolicy metricsRetentionPolicy = new RetentionPolicy(); metricsRetentionPolicy.setEnabled(true); metricsRetentionPolicy.setDays(new BigInteger("1")); metrics.setVersion(1); metrics.setRetentionPolicy(metricsRetentionPolicy); storageServiceProperties.setMetrics(metrics);

String storageprop = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + marshall(storageServiceProperties); HttpPut putRequest = new HttpPut(spUrl);

StringEntity input = new StringEntity(storageprop); input.setContentType("text/plain");

putRequest.setEntity(input);

String auth = signRequest(putRequest.getURI().toURL(), "acptest2", key); putRequest.addHeader("x-ms-date", getDate()); System.out.println("Date  : "+getDate()); putRequest.addHeader("x-ms-version", "2011-08-18"); putRequest.addHeader("Authorization", auth); putRequest.addHeader("Host", "acptest2.blob.core.windows.net");

HttpResponse response; try { response = client.execute(putRequest);

System.out.println("Status code: "+response.getStatusLine().getStatusCode()); String responseString = new BasicResponseHandler().handleResponse(response); System.out.println(responseString); } catch (Exception e) { e.printStackTrace(); } }

public static String getDate() { SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String date = fmt.format(Calendar.getInstance().getTime()) + " GMT"; return date;

}

Java_UserA (talk) 15:46, 14 August 2013 (EEST)

Galazzo -

Hi Anite,

I'll give an eye on your code as soon as possible, but please be sure your management key is correct. If yes please tell me to don't look for an not existing error.

Regards,

Sebastiano

galazzo (talk) 11:44, 20 August 2013 (EEST)

 

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×