The Internet Direct (Indy) 10 HTTP server class TIdHTTPServer does support HTTP file upload with multipart/form-data encoding. The solution below is based on code in the Indy and Delphi newsgroups. Please note that a patch in the Indy library is required, as shown on Stackoverflow in Indy MIME decoding of Multipart/Form-Data Requests returns trailing CR/LF.

Usage

If the demo server runs, open a web browser and navigate to the URL http://127.0.0.1:8080, there you will find the upload form

Neue Bitmap

Source

The full source code can be found here: Indy MIME decoding of Multipart/Form-Data Requests returns trailing CR/LF.

Advertisement

4 thoughts on “Indy HTTP server: multipart/form-data file upload example

  1. I find out that if 3 files (mp3, txt and jpg) were uploaded on the server using the code provided in the original question even with the patch proposed by Remi Lebeau were corrupted. But I have to underlined that Remi provides 99,5% of the information to solve the problem. The problem was not only the CR and LF characters added at the end of the files but almost every bytes of data were modified. The solution is to use a binary encoding (like 8 bit encoding but without the limit on the size of the attachments) for all content type with the exception of application/mac-binhex40 that remains encoded using binhex40. So 7 bit should never be used along with modern browser. I have created a blog post [1] with the code source that work well for me. The files used for testing are also available in this post. In my sample programmed I derived a class from the Indy Component, so that the Indy component not have to be modified. I also change the html file served by the server so that it also support multi selection.

    [1] https://alexandrejacquot.programming.next-step.space/index.php/2021/01/06/files-upload-with-delphi-on-the-server-and-pure-html-on-the-internet-browser-side/

    1. Thank you for your post! Maybe you can also submit a pull request with your modification to the Indy project on GitHub. I have not yet tested your code but surely will as soon as there is some time for it.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s