如何在android中使用MultiPartEntity在服务器上上传3gp文件?
我必须使用MultipartEntity将3gp音频文件上传到我的服务器。我正在使用此代码,但仍然无法上载3gp文件如何在android中使用MultiPartEntity在服务器上上传3gp文件?,android,file,file-upload,http-post,send,Android,File,File Upload,Http Post,Send,我必须使用MultipartEntity将3gp音频文件上传到我的服务器。我正在使用此代码,但仍然无法上载3gp文件 FileInputStream is = new FileInputStream(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+
FileInputStream is = new FileInputStream(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+
"/" + nameOfFile));
byte[] data = IOUtils.toByteArray(is);
InputStreamBody isb = new InputStreamBody(new
ByteArrayInputStream(data),nameOfFile);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.****.com/places/uploadVideo");
httppost.setHeader("Content-Type", "audio/3gpp");
MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartContent.addPart("video", isb);
Log.d("Audio length", isb.getFilename()+" "+isb.getMediaType()+ isb.getMimeType());
httppost.setEntity(multipartContent);
HttpResponse res =httpclient.execute(httppost);
InputStream input = res.getEntity().getContent();
BufferedReader rd = new BufferedReader(new InputStreamReader(input,"UTF-8"),input.toString().length());
String line;
StringBuilder sb = new StringBuilder();
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
String uploadresponse = sb.toString();
Log.d("Upload Pic Response",uploadresponse );
请告诉我哪里出错了
LogCat响应
02-18 19:58:51.912: D/Audio length(3157): 1329575327359.3gp applicationapplication/octet-stream
02-18 19:58:52.412: D/dalvikvm(3157): GC_FOR_MALLOC freed 2359 objects / 161592 bytes in 56ms
02-18 19:58:54.002: I/Resources(3157): Loaded time zone names for en_US in 200ms.
02-18 19:58:54.012: D/Upload Pic Response(3157): <strong>app/controllers/places_controller.php</strong> (line <strong>425</strong>)<pre class="cake-debug">Array( [controller] => places [action] => uploadVideo [named] => Array ( ) [pass] => Array ( ) [plugin] => [form] => Array ( ) [url] => Array ( [url] => places/uploadVideo ))</pre>{"response":{"status":0,"mesg":"No Video data present in the request"},"data":null}
02-18 19:58:51.912:D/音频长度(3157):1329575327359.3gp应用程序/八位字节流
02-18 19:58:52.412:D/dalvikvm(3157):GC_FOR_MALLOC在56毫秒内释放了2359个对象/161592个字节
02-18 19:58:54.002:I/Resources(3157):以200ms为单位加载en_US的时区名称。
02-18 19:58:54.012:D/Upload Pic Response(3157):app/controllers/places\u controller.php(line425)数组([controller]=>places[action]=>uploadVideo[named]=>Array()[pass]=>Array()[plugin]=>form]=>Array()[url]=>Array([url]=>places/uploadVideo)){“response”:{“status”:0,“mesg”:“请求中不存在视频数据”},“data”:null}
试试这个
File f1 = null;
ContentBody cbFile, cbFile1;
// videofilename is the entire path file for eg. /mnt/sdcard/12345abc.3gpp
f1 = new File(videofilename);
cbFile = new FileBody(f1, "video/3gpp");
mpEntity.addPart("uservideo", cbFile);
让我知道这是否有效。它不起作用。.同样的问题。我上传了一个扩展名为.3gp的音频文件。你在这个日志中得到了什么。d(“音频长度”,isb.getFilename()+“”+isb.getMediaType()+isb.getMimeType());?Kinldy chk,我在问题中添加了logcat。