0
我試圖從Android應用程序向服務器發送mp3文件。我用這個方法android async http發送mp3文件。從Android向服務器發送mp3文件時遇到困難
這是我的代碼。
try {
params1.put("file", new ByteArrayInputStream(MeetingFragment.mediafile));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
AsyncClientHandler.post("events/Uploadrecording/5", params1,
new AsyncHttpResponseHandler() {
@Override
public void onFailure(int statusCode,
Throwable error, String content) {
// TODO Auto-generated method stub
super.onFailure(statusCode, error, content);
Log.i("filename",myFile.toString());
Toast.makeText(_context, "failiure push"+ProjectEventFragment.event.eve_id, Toast.LENGTH_SHORT).show();
}
@SuppressWarnings("deprecation")
@Override
public void onSuccess(int statusCode,
Header[] headers, String content) {
// TODO Auto-generated method stub
super.onSuccess(statusCode, headers, content);
Toast.makeText(_context, "success push"+ProjectEventFragment.event.eve_id, Toast.LENGTH_SHORT).show();
Log.i("Successpush",content.toString());
}
});
我已經給出了正確的URL,並且我也獲得了該文件的值。但是它會成功。任何人都可以幫我解決這個問題嗎?如果你知道任何替代方式,那麼請建議我。提前致謝。
public static byte[] mediafile;
public static String record_file=null
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(record_file);
mediafile = record_file.getBytes();
我去的成功的部分與我上面的代碼。我試圖檢查我發送的文件。它給了我一些空值的數字。 (例如 - 14145345-null)。我只是做了音頻記錄並分配給字符串變量,然後再轉換爲字節數組。我修改了我的問題。請檢查一下。 – user3663600 2014-10-31 12:31:38