Handling multipart/form-data with Mux or HTTP

Hi everyone! I’m trying to handle the upload of files (several files at the same time) using Mux.

I would like to be able to loop over the input parts and for each of them :

  1. get the name of the file
  2. get the content of the file

With Mux, in req[:data] there’s a Vector{UInt8}. That’s pretty much where I am now :sweat_smile:.

In this post @rssdev10 gives a function that can extract the content of a file from a Vector{UInt8}.
It works from a Vector{UInt8} previously serialized (using serialize()) but doesn’t work (oddly enough) on applied to req[:data] in the route() function, which is the normal scenario. It also doesn’t extract the filename.

Has anyone succeeded in handling multipart/form-data with Mux or HTTP?

Hi, I believe that multipart data processing should be a part of HTTP.jl. Actually I have prepared simple code sample for parsing HTTP.jl data but not ready to dive into full development of that library. It would be good to have some comments from key developers…

And regarding web app with file uploading see https://github.com/rssdev10/JWebImageDemo.jl/blob/master/src/run.jl

1 Like

The code from @rssdev10 in this post actually works fine (for uploading one file).

If using Mux, the code is then the following:

file_content = parse_multipart(req[:data])
write("test.png",file_content)

With parse_multipart being given in the post aforementioned

There is a better solution that can handle several files,
here