[英]Android Multipart image upload to Azure
有什么方法可以将图像从Android设备上传到Azure存储桶?
Try this a let me know whether it work for you or not 试试这个让我知道它是否对您有用
public HttpResponse request(String filePath, String url) {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams()
.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(url);
MultipartEntity mpEntity = new MultipartEntity();
File file = new File(filePath);
ContentBody cbFile = new FileBody(file, "image/png");
mpEntity.addPart(PARAMETER_SIGNATURE, cbFile);
try {
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response;
response = httpclient.execute(httppost);
httpclient.getConnectionManager().shutdown();
return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
AsyncTask class AsyncTask类
public class Task extends AsyncTask<String, Void, HttpResponse> {
private Exception exception;
protected void onPostExecute(HttpResponse response) {
Log.i("Loader ", response.getStatusLine().toString());
// if (resEntity != null) {
// System.out.println(EntityUtils.toString(resEntity));
// }
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
Log.i("Loader ", "upload ok");
} else {
Log.i("Loader ", "upload failed");
}
}
@Override
protected HttpResponse doInBackground(String... params) {
try {
return request(params[0], params[1]);
} catch (Exception e) {
this.exception = e;
return null;
}
}
public Exception getException() {
return exception;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.