我有一个Android 2.1应用程序。 我需要从我的Azure存储中的应用程序下载文件。 我无法使用Azure提供的API,因为我的Android版本已经过时了。 所以,我尝试通过Rest服务调用下载该文件。 我不知道为什么我没有成功地做到这一点
我试图做的事情:
private String _url = "https://fake_azure_acount_name.blob.core.windows.net/";
private final String _thisClassName = "StorageProvider";
private final String _azurAcountName = "fake_azure_acount_name";
public String GetImage(String imagePath)
{
String image = ExecuteGetRequest(imagePath, "Could not succeed get the requested image");
return image;
}
private String ExecuteGetRequest(String getRequest, String errorMassageIfFailes)
{
DefaultHttpClient httpclient = new DefaultHttpClient();
try
{
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(new HttpGet(_url + getRequest));
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
JSONTokener tokener = new JSONTokener(json);
JSONArray finalResult = new JSONArray(tokener);
return json;
}
catch(Exception ex)
{
Log.e(_thisClassName, errorMassageIfFailes, ex);
return null;
}
finally
{
try
{
httpclient.getConnectionManager().shutdown();
}
catch(Exception ex)
{
Log.e(_thisClassName, "Failed to close http connection", ex);
}
}
}
这样做的正确方法是什么?
答案 0 :(得分:0)
由于您直接使用REST API,我强烈建议您阅读相应的API文档:Get Blob。它看起来不像您正在进行共享密钥身份验证,因此您有两个选择:
有关身份验证的详情,请参阅Authentication for the Azure Storage Services和Delegating Access with a Shared Access Signature。