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存储,所以我需要密钥。这只是一个例子,关键要长得多 –
好吧,我不知道,只是认为这是关键,所以想到提醒你。 –