Microsoft聲明獲取Blob只是一個普通的http獲取https://myaccount.blob.core.windows.net/mycontainer/myblob
。但是當我擁有一個賬戶+共享密鑰時,如何格式化字符串?GET文件的私有blob存儲url的格式。 Rest API
我知道有一個Azure的SDK,但我創造一個「附加」到現有的Java EE系統,並且不能在Azure上運行,所以我使用REST API。這是我試過到目前爲止:
String account = "myaccount";
String key = "243fedfsdf23f4f";
String protocol = "http";
String storageConnectionString = String.format("DefaultEndpointsProtocol=%s;AccountName=%s;AccountKey=%s", protocol, account, key);
System.out.println(storageConnectionString);
URL url = new URL("https://mysite.azureweb.com/myfile.txt");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
// Buffer the result into a string
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
字符串可能需要一些的Base64編碼?
更新
HTTP請求看起來像GET https://myAccount.blob.core.windows.net/myDir/myfile.txt HTTP/1.1 x-ms-date: Thu, 01 Oct 2015 12:56:11 GMT x-ms-version: 2015-02-21 Authorization: SharedKey myAccount:asdfkjsladjfsdf827fhwf298f924f92723dfh23f273f2h7h4f Host: myAccount.blob.core.windows.net
我 「只是」 需要打包到這個請求得到文件/mydir/myfile.txt
您可能想要刪除已放入問題中的密鑰並更改/刪除Azure服務器上的密鑰值。 –
私人blob存儲,所以我需要密鑰。這只是一個例子,關鍵要長得多 –
好吧,我不知道,只是認爲這是關鍵,所以想到提醒你。 –