What should a Multipart HTTP request with multiple files look like? [duplicate]

Well, note that the request contains binary data, so I’m not posting the request as such – instead, I’ve converted every non-printable-ascii character into a dot (“.”). POST /cgi-bin/qtest HTTP/1.1 Host: aram User-Agent: Mozilla/5.0 Gecko/2009042316 Firefox/3.0.10 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://aram/~martind/banner.htm Content-Type: multipart/form-data; boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f Content-Length: 514 … Read more

Send a file as multipart through XMLHttpRequest

That’s only possible with the XHR FormData API (previously known being part of as “XHR2” or “XHR Level 2”, currently known as “XHR Advanced Features”). Given this HTML, <input type=”file” id=”myFileField” name=”myFile” /> you can upload it as below: var formData = new FormData(); formData.append(“myFile”, document.getElementById(“myFileField”).files[0]); var xhr = new XMLHttpRequest(); xhr.open(“POST”, “myServletUrl”); xhr.send(formData); XHR … Read more

Example of multipart/form-data

EDIT: I am maintaining a similar, but more in-depth answer at: https://stackoverflow.com/a/28380690/895245 To see exactly what is happening, use nc -l or an ECHO server and an user agent like a browser or cURL. Save the form to an .html file: <form action=”http://localhost:8000″ method=”post” enctype=”multipart/form-data”> <p><input type=”text” name=”text” value=”text default”> <p><input type=”file” name=”file1″> <p><input type=”file” … Read more

How to upload images to server in Flutter?

Use MultipartRequest class Upload(File imageFile) async { var stream = new http.ByteStream(DelegatingStream.typed(imageFile.openRead())); var length = await imageFile.length(); var uri = Uri.parse(uploadURL); var request = new http.MultipartRequest(“POST”, uri); var multipartFile = new http.MultipartFile(‘file’, stream, length, filename: basename(imageFile.path)); //contentType: new MediaType(‘image’, ‘png’)); request.files.add(multipartFile); var response = await request.send(); print(response.statusCode); response.stream.transform(utf8.decoder).listen((value) { print(value); }); } name spaces: import … Read more

How can I make a multipart/form-data POST request using Java?

We use HttpClient 4.x to make multipart file post. UPDATE: As of HttpClient 4.3, some classes have been deprecated. Here is the code with new API: CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost uploadFile = new HttpPost(“…”); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(“field1”, “yes”, ContentType.TEXT_PLAIN); // This attaches the file to the POST: File f = new File(“[/path/to/upload]”); … Read more