我正在将文件(图像、视频和音频)从 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();
}
});