Android:How to upload .mp3 file and image to http server?

怎甘沉沦 提交于 2019-11-29 07:36:47

So, you want to send multiple files in one HTTP request? I've never done this myself, but according to the RFC, just add another body to the message in which you send the audio, it should look something like this:

    dos = new DataOutputStream(conn.getOutputStream());
    dos.writeBytes(twoHyphens + boundary + lineEnd);
    dos.writeBytes("Content-Disposition: form-data; name=\"file_name\";filename=\""
        + fileName + "\"" + lineEnd);
    dos.writeBytes(lineEnd);
    // Code for sending the image....
    dos.writeBytes(lineEnd);


    dos.writeBytes(twoHyphens + boundary + lineEnd);
    dos.writeBytes("Content-Disposition: form-data; name=\"file_name_audio\";filename=\""
        + fileNameAudio + "\"" + lineEnd);
    dos.writeBytes(lineEnd);
    // Code for sending the MP3
    dos.writeBytes(lineEnd);
    dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

Make sure that the names of both parts are different (depending on the server software).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!