我只是想通过代码将文件上传到服务器,如果我从模拟器访问文件,它工作正常,
路径data/app/07312012_135528.3gp并获得服务器响应200,OK
但是当我通过设备访问要上传的文件时出现错误400, 当文件存在于SDCard中时出现错误请求,并且它通过了File.exists()检查。
我的手机是三星 Galaxy Ace
HttpPost postRequest = new HttpPost(ServerURL);
MultipartEntity reqEntity = new MultipartEntity();
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "tdsongdata/07312012_135528.3gp");
// path becomes "/mnt/sdcard/tdsongdata/07312012_135528.3gp"
if(yourFile.exists())
{
reqEntity.addPart("email", new StringBody("esetylo@gmail.com"));
reqEntity.addPart("password", new StringBody("123"));
reqEntity.addPart("title", new StringBody("The new file"));
reqEntity.addPart("musicData", new FileBody(yourFile));
}
但是当我尝试从设备中的同一路径播放它时,它会成功播放音频
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("/mnt/sdcard/tdsongdata/07312012_135528.3gp");
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
看不懂问题出在哪里,求大神帮忙