0

I am trying to upload a video to the server using the post method, but I am getting

FileNotFoundException

Here's my code. In the path variable I am getting "content:/media/external/video/media/2"

public class VideoPlayUploadActivity extends Activity {
private VideoView video_play;
private Button accept_and_go;
private Button reject_and_do;
Uri vid;
String user;
String question;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_view);

    video_play = (VideoView) findViewById(R.id.videoView1);
    accept_and_go = (Button) findViewById(R.id.button_accept_and_go_over_video);
    reject_and_do = (Button) findViewById(R.id.button_reject_and_do_over_video);

    Intent extras = getIntent();
    vid = Uri.parse(extras.getStringExtra("uri"));

    if (vid == null) {
        Toast.makeText(VideoPlayUploadActivity.this, "No Video",
                Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(VideoPlayUploadActivity.this,
                "Playback: " + vid.getPath(), Toast.LENGTH_LONG).show();
        MediaController mc = new MediaController(this);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        video_play.setMediaController(mc);
        video_play.setVideoURI(vid);
        video_play.start();

    }
    accept_and_go.setOnClickListener(accept_go_listener);
}

private View.OnClickListener accept_go_listener = new View.OnClickListener() {

    @Override
    public void onClick(View v) {

        // TODO Auto-generated method stub
        String path = vid.getPath();
        File file = new File(path);
        try {
            HttpClient client = new DefaultHttpClient();
            String postURL = "xxxxxxxxxxxxxxxxxxxxxxxxupdateAnswerFile";
            HttpPost post = new HttpPost(postURL);
            FileBody bin = new FileBody(file);
            StringBody user = new StringBody("1");
            StringBody question = new StringBody("25");
            MultipartEntity reqEntity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            reqEntity.addPart("user", user);
            reqEntity.addPart("question", question);
            reqEntity.addPart("answer", bin);
            post.setEntity(reqEntity);
            HttpResponse response = client.execute(post);
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                Log.i("RESPONSE", EntityUtils.toString(resEntity));
            }
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "exception", 0).show();
            e.printStackTrace();
        }
    }
};
private View.OnClickListener reject_do_listenter = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }
};
}

Please tell me where i am going wrong.

Chuck
  • 998
  • 8
  • 17
  • 30
Arshdeep_somal
  • 206
  • 1
  • 13
  • content:// is not a file, it cannot be used in a FileBody. try an inputstreamBody and open the InputStream with contentResolver.openInputStream(path) – njzk2 Sep 26 '12 at 07:59

1 Answers1

1

Please follow the below link

Get filename and path from URI from mediastore

It's showing error because you are not converting the content path into real path.

It works for me.

Hope it helps.

Community
  • 1
  • 1
moDev
  • 5,248
  • 4
  • 33
  • 63