android httpclient

android httpclient,android,httpclient,Android,Httpclient,如何使用httppost将50mb文件传输到web服务器。 尝试传输文件时,会显示内存不足错误。 我们可以使用压缩编码吗?怎样?给出一些代码片段 多谢各位 编辑: 代码如下: InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(f), -1); reqEntity.setContentType("binary/octect-stream"); reqEntity.setChunked(true); ht

如何使用httppost将50mb文件传输到web服务器。 尝试传输文件时,会显示内存不足错误。 我们可以使用压缩编码吗?怎样?给出一些代码片段

多谢各位

编辑: 代码如下:

InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(f), -1);
reqEntity.setContentType("binary/octect-stream"); 
reqEntity.setChunked(true);
httppost.setEntity(reqEntity);

使用
InputStreamEntity
,因为它不会将整个文件加载到内存中。这样做:

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://localhost/upload");

File file = new File("/path/to/myfile");
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();

使用
InputStreamEntity
,因为它不会将整个文件加载到内存中。这样做:

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://localhost/upload");

File file = new File("/path/to/myfile");
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();

您现在使用的是什么方法?InputStreamEntity reqEntity=new InputStreamEntity(新文件InputStream(f),-1);requentity.setContentType(“二进制/八进制流”);reqEntity.setChunked(真);httppost.setEntity(reqEntity);您现在使用的是什么方法?InputStreamEntity reqEntity=new InputStreamEntity(新文件InputStream(f),-1);requentity.setContentType(“二进制/八进制流”);reqEntity.setChunked(真);httppost.setEntity(reqEntity);谢谢。但是我如何在web服务器(struts2)上使用Struts文件上载拦截器获取文件:谢谢。但是我如何在web服务器(struts2)上使用Struts文件上载拦截器获取文件: