I'am trying to send a mp3 file from my Android application to Server. I'am using this method android async http to send mp3 file.
This is my code.
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());
}
});
I have given the correct URL and i also getting value for the file. But it is going to success part. Could anyone help me to solve this problem? If you know any alternate way then please suggest me. Thanks in advance.
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();