upload an image and audio in One request in android

前端 未结 1 1889
庸人自扰
庸人自扰 2020-11-27 07:58

How to upload an image and audio together in android? I was successful in uploading an image and audio in one request but how to add multiple files.

I referred this

相关标签:
1条回答
  • 2020-11-27 08:42

    Just use the httpmime-4.0.jar and apache-mime4j-0.4.jar and set the entity as MultipartEntity. you can use as many file as you want.

    Here is the stuff,

    HttpPost httpost = new HttpPost("url for upload file");
    
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("myIdentifier", new StringBody("somevalue"));
    entity.addPart("myImageFile", new FileBody(imageFile));
    entity.addPart("myAudioFile", new FileBody(audioFile));
    
    httpost.setEntity(entity);
    HttpResponse response;
    response = httpclient.execute(httpost);
    

    and for php side you can use these entity identifier names "myImageFile" and "myAudioFile" and move these files in appropriate folder.

    0 讨论(0)
提交回复
热议问题