Sending images and videos to server in android

前端 未结 3 711
走了就别回头了
走了就别回头了 2021-01-01 05:22

I am creating an android application for taking photos and videos. After capture images I want to send this image with date and some text to web server. In server side I am

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 05:58

    You can do this with a Multipart post request:(This way, you dont need to create json)

            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(serverURL);
            MultipartEntity postEntity = new MultipartEntity();
            File file = new File("Your File path on SD card");
            postEntity.addPart("fileupload", new FileBody(file, "image/jpeg"));
            postEntity.addPart("loginKey", new StringBody(""+loginKey));
            postEntity.addPart("message", new StringBody(message));
            postEntity.addPart("token", new StringBody(token));
            post.setEntity(postEntity);
            response = client.execute(post);
    

    You have to add this mime4j library.

提交回复
热议问题