我上传文件(图片,视频和音频)从Android端到PHP服务器。对于小文件来说,它工作得很好。但对于大文件,它会给出意想不到的结果,比如文件上传,但在android端,它会给出超时异常。所以请帮助我,我如何处理文件上传的所有场景。如何使用HttpMultipart实体以及如何针对不同大小的文件设置相对超时。我的代码是:
File myFile = new File(filePath);
RequestParams params = new RequestParams();
try {
params.put("uploaded_file", myFile);
} catch (FileNotFoundException e) {
}
URL=getResources().getString(com.newing.R.string.server_adderess)+URL+fileType+"&lessonID="+LessonID;
client.post(URL, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
Log.w("async", "success!!!!");
UtilityFunctions.showNotification(getApplicationContext(),
"File uploading completed.");
stopSelf();
}
@Override
public void onFailure(Throwable error) {
Log.w("async", "failure!!!!");
UtilityFunctions.showNotification(getApplicationContext(),
"File couldn't upload. Please try later.");
stopSelf();
}
});发布于 2014-03-28 05:57:47
你可以尝试使用Ion是一个很棒的异步网络和图像加载https://github.com/koush/ion库
上传文件的简单示例
Ion.with(getContext(), "https://koush.clockworkmod.com/test/echo") .uploadProgressBar(uploadProgressBar) .setMultipartFile("filename.zip", new File("/sdcard/filename.zip")) .asJsonObject() .setCallback(...)
有关更多示例和wiki,请查看项目网站
https://stackoverflow.com/questions/20993844
复制相似问题