我想让我的应用程序使用下面的代码将图像上传到网络服务器。它有时会起作用,但似乎也会因内存错误而失败。如果文件大小很大,有人可以发表一个如何完成这个任务的例子吗?此外,我正在构建这个支持1.5和以上。我不介意给我的代码在上传之前调整图像的大小。Android - 将大图像上传到服务器
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlString);
File file = new File(nameOfFile);
FileInputStream fileInputStream = new FileInputStream(file);
InputStreamEntity reqEntity = new InputStreamEntity(fileInputStream, file.length());
httppost.setEntity(reqEntity);
reqEntity.setContentType("binary/octet-stream");
HttpResponse response = httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
responseEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
时出现内存问题所产生的图像是不完整的,似乎,这意味着它在它下面磨片灰色像素重新失败。 – BBCM 2011-02-09 05:22:03
您是否找到了该问题的解决方案? @BBCM – Amina 2014-05-09 10:51:00