php – Android:使用MultipartEntity上传大文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Android:使用MultipartEntity上传大文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1848字,纯文字阅读大概需要3分钟。
内容图文
根据这个答案“Android upload video to remote server using HTTP multipart form data”我做了所有的步骤.
但我不知道我如何编码服务器端!我的意思是一个PHP简单的页面,为我的reauest敌人上传提供服务.
另一个问题是:YOUR_URL(以下代码段的第3行)必须是该PHP页面的地址吗?
private void uploadVideo(String videoPath) throws ParseException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(YOUR_URL);
FileBody filebodyVideo = new FileBody(new File(videoPath));
StringBody title = new StringBody("Filename: " + videoPath);
StringBody description = new StringBody("This is a description of the video");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("videoFile", filebodyVideo);
reqEntity.addPart("title", title);
reqEntity.addPart("description", description);
httppost.setEntity(reqEntity);
// DEBUG
System.out.println( "executing request " + httppost.getRequestLine( ) );
HttpResponse response = httpclient.execute( httppost );
HttpEntity resEntity = response.getEntity( );
// DEBUG
System.out.println( response.getStatusLine( ) );
if (resEntity != null) {
System.out.println( EntityUtils.toString( resEntity ) );
} // end if
if (resEntity != null) {
resEntity.consumeContent( );
} // end if
httpclient.getConnectionManager( ).shutdown( );
}
解决方法:
这段代码工作正常,我应该使用的PHP代码就像这样简单:
<?php
$file_path = "uploads/";
$file_path = $file_path . basename( $_FILES['videoFile']['name']);
if(move_uploaded_file($_FILES['videoFile']['tmp_name'], $file_path)) {
echo "success";
} else{
echo "upload_fail_php_file";
}
?>
请注意,videoFile必须与之完全匹配
reqEntity.addPart(“videoFile”,filebodyVideo);
您可能面临的最重要的问题是服务器配置中的post_max_size和upload_max_filesize的默认值!由于默认值太小,当您尝试上传大文件时,PHP脚本返回:“upload_fail_php_file”,没有错误或异常抛出.所以请记住将这些值设置得足够大……
享受编码.
内容总结
以上是互联网集市为您收集整理的php – Android:使用MultipartEntity上传大文件全部内容,希望文章能够帮你解决php – Android:使用MultipartEntity上传大文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。