Sending images and videos to server in android

前端 未结 3 697
走了就别回头了
走了就别回头了 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.

    0 讨论(0)
  • 2021-01-01 05:59

    You can use this code in your asynctask:

    File file = new File("Your File path on SD card");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httpost = new HttpPost("YourUrl");
    
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("YourKey",new StringBody("Your Text"));
    entity.addPart("File", new FileBody(file));
    httpost.setEntity(entity);
    
    
    HttpResponse response = httpclient.execute(httpost);
    
    0 讨论(0)
  • 2021-01-01 06:05

    try this to uplaod text ,image to server in asynctask

               FileBody filebodyVideo = new FileBody(new File(
                        "Sd Card VideoPath"));
    
                FileBody filebodyVideo1 = new FileBody(new File("Video Upload url"));
    
                StringBody Title= new StringBody("Put Title Here");
    
                StringBody description= new StringBody("Put Desc Here");
    
    
    
    
                MultipartEntity reqEntity = new MultipartEntity();
    
                reqEntity.addPart("image", filebodyVideo);
    
                multipartContent.addPart("Title", Title);
    
                multipartContent.addPart("Description", description);
    
    
                httppost.setEntity(multipartContent);
    
    0 讨论(0)
提交回复
热议问题