我尝试将音频文件从android上传到node.js服务器,但不幸的是,在服务器上传的文件没有播放。它在VLC媒体播放器中播放时显示错误“没有合适的解码器模块:VLC不支持音频或视频格式'samr'。”
这是我的Android代码:
String name = aurl[0];
String groupid = aurl[0];
File file = new File(aurl[1]);
//ByteArrayBody byteArrayBody = new ByteArrayBody(audioData, name);
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//multipartEntity.addPart("uploadDocument", byteArrayBody);
ContentBody cb = new FileBody(file,"video/mp4");
multipartEntity.addPart("uploadDocument",cb);
HttpClient httpClient = new DefaultHttpClient();
System.out.println("Befor Call ...................................");
String requestUri = Constants.URI_SERVER + "/upload/"+ groupid +"/FromAndroidkycUploadingAudio";
HttpPost httpPost = new HttpPost(requestUri);
httpPost.setEntity(multipartEntity);
Header header = new BasicHeader(Constants.FIELD_REQUEST_SOURCE, Constants.FIELD_ANDROID);
httpPost.addHeader(header);
HttpResponse httpResponse = httpClient.execute(httpPost);
if(httpResponse.getStatusLine().getStatusCode() == 200) {
toastMsg = Constants.MSG_UPLOAD_SUCCESS;
} else {
toastMsg = Constants.MSG_UPLOAD_FAILURE;
}
我的服务器端Node.js代码:
var fs1=require('fs');
var util = require('util');
var is = fs1.createReadStream(req.files.uploadDocument.path)
var os = fs1.createWriteStream("client_documents/"+"Audio1"+".mp4");
util.pump(is, os, function() {
//fs1.unlinkSync(req.files.uploadDocument.path);
console.log('It\'s moved!');
});
请建议我任何解决方案......