# HTTP multipart/form-data processing by server

**URL:** <https://discourse.julialang.org/t/http-multipart-form-data-processing-by-server/24076>\
**Category:** Web Stack\
**Created:** [May 10, 2019, 2:18pm UTC](https://discourse.julialang.org/t/http-multipart-form-data-processing-by-server/24076 "2019-05-10T14:18:09Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![tencnivel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tencnivel/32/8662_2.png) [@tencnivel](https://discourse.julialang.org/u/tencnivel)\
**Post date:** [August 4, 2019, 1:42pm UTC](https://discourse.julialang.org/t/http-multipart-form-data-processing-by-server/24076/6 "2019-08-04T13:42:19Z")

</div>

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](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:

```julia
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:

```julia
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

```

---

_[View the full topic](https://discourse.julialang.org/t/http-multipart-form-data-processing-by-server/24076)._
