我需要将/home/downloads/pics.jpg
的图片发送到Android手机。我已经看到了一些有关如何将图像从服务器发送到Android设备的信息。例如:this link
请给我一些关于如何在服务器部分处理此问题的建议?
答案 0 :(得分:0)
String url = "http://yourserver/image.jpg";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
// show error
}