0

I am just trying to upload file to server through the code it working fine if I access file from Emulator,

path data/app/07312012_135528.3gp and gets server response 200, OK

but when I access file to upload through Device is gives error 400, Bad Request while file is present in SDCard and it passes the File.exists() check.

My Phone is Samsung 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("[email protected]"));
    reqEntity.addPart("password", new StringBody("123"));
    reqEntity.addPart("title", new StringBody("The new file"));         
    reqEntity.addPart("musicData", new FileBody(yourFile));
}

But When I try to play it from the same path in Device it plays the Audio successfully

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();
}

I could not understand where the problem is, please help

8
  • If you get a different HTTP status code, the problem should be on your server. Commented Aug 4, 2012 at 23:04
  • Is your device in "Charge only" mode? Commented Aug 5, 2012 at 0:10
  • How to check if its in "charge only" mode. Commented Aug 5, 2012 at 4:07
  • Did you add the internet permission to your manifest? Commented Aug 6, 2012 at 16:59
  • yes I added INTERNET and WRITE_EXTERNAL_STORAGE permissions in manifest ... it seems there is some file access problem .. but how to solve it ????? Commented Aug 6, 2012 at 17:18

1 Answer 1

1

Change your phone language to English (United States). Reboot your Device and try again.

Sign up to request clarification or add additional context in comments.

1 Comment

Any chance you could explain why this is a solution? I'm curious how language affects his problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.