HTTP multipart/form-data processing by server

thanks for pointing the pull-request! With a few minor modifications it works

In case other people need it, here are the steps (and hopefully this will not be needed anymore in not so long) to incorporate it in a project:

  1. Download parsemultipart.jl from the repository (https://github.com/JuliaWeb/HTTP.jl/blob/a833cefafe67e39b283281217163c1c803f469ea/src/parsemultipart.jl) and put it somewhere in your project
  2. Replace Line 92:
    push!(d, Multipart(string(filename), io, string(contenttype), string(""), string(name)))
    by the following:
    push!(d, Multipart(string(filename), io, string(contenttype), string("")))

By doing so, we don’t need to modify the struct HTTP.Multipart.

If using Mux you will also need this method so that you can pass the body and not the request itself:

function parse_multipart_form(body::Vector{UInt8}, content_type::String)
    m = match(r"multipart/form-data; boundary=(.*)$", content_type)
    m === nothing && return nothing
    parse_multipart_body(body, m[1])
end

You can then call parse_multipart_form using either the request or the request body.

If using Mux it looks like this:

contentType =
    filter(x -> x.first == "Content-Type",
            req[:headers])[1].second
contentType = string(contentType)

parts = parse_multipart_form(req[:data],
                                contentType)        
    
for p in parts
    # Save the file in the temp directory
    destfile = tempname()
    @info "Saving $(p.filename) to @destfile"
    write(destfile,take!(p.data))

end # ENDOF for-loop on message multiparts