我的Android应用程序正在使用HTTP Post发送一个大文件(或多或少50mb) 这是我的代码:
protected String doInBackground(String... params) {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(params[0]);
String responseLine = null;
try {
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("file", new FileBody(mFile));
httpPost.setEntity(entity.build());
HttpResponse response = httpClient.execute(httpPost, localContext);
StatusLine statusLine = response.getStatusLine();
// if the response from my server is length = 2 that means everything
// went ok
if (statusLine.getStatusCode() == HttpStatus.SC_OK && response.getEntity().getContentLength() == 2) {
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
//blabla..
}
return "ok";
}
我的服务器上传php代码;
// log in files
file_put_contents( 'screen/debug' . time() . '.log', var_export( $_FILES, true));
$objFile = $_FILES["file"];
$target_path = $_SERVER['DOCUMENT_ROOT'] . "/test/" . basename($_FILES['file']['tmp_name']);
if( move_uploaded_file( $objFile["tmp_name"], $target_path) ) {
print "ok";
} else {
print "There was an error uploading the file, please try again!";
}
因此,这段代码大部分时间都能正常运行。但有时(经常忽略)上传失败。在我的服务器错误日志中,我收到PHP错误 UPLOAD_ERR_PARTIAL
我的服务器是一个测试服务器 upload_max_filesize = 400M post_max_size = 512M max_execution_time = 3600 max_input_time = 3600;每个脚本可能花费在解析请求数据上的最长时间 memory_limit = 1024M;脚本可以使用的最大内存量
有人看到我为什么会收到这个错误吗?