使用Long Time Android将文件上传到服务器

时间:2014-05-05 07:23:14

标签: java android androidhttpclient

我已经开发了应用程序,我将音频文件和接收器信息发送到服务器,它的工作很多次上传需要很长时间并导致ConnectionTimeout异常。

我正在使用的代码:

BasicHttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 120000);
HttpConnectionParams.setSoTimeout(httpParameters, 120000);
HttpClient httpClient = new DefaultHttpClient(httpParameters);
postStr = new Gson().toJson(audioBean);
File file = new File(audioBean.getFilePath());
ContentBody contentBody = new FileBody(file, "audio/wav");
MultipartEntity mpEntity = new MultipartEntity();
mpEntity.addPart("audio", new StringBody(postStr));
mpEntity.addPart("file", contentBody);
httpPost.setEntity(mpEntity);
HttpResponse httpResponse = httpClient.execute(httpPost);
inputStream = httpResponse.getEntity().getContent();

上面的代码在线程中运行,请告诉我如何提高性能

0 个答案:

没有答案