HTTP multipart/form-data processing by server

#1

Is any way to parse multipart/form-data by HTTP functions?

I’m trying to upload and process a file in Bukdu app with

  <form method="post" enctype="multipart/form-data">...</form>

The request.body is correct for multipart. But I don’t see any way to convert it to HTTP.Multipart. The are only client related methods at https://github.com/JuliaWeb/HTTP.jl/blob/master/src/multipart.jl

Should I implement that functionality self? Or may be it is already implemented somewhere? Any ideas why it is not inside HTTP?

I’m talking about a body like:

"-----------------------------189075738616438618431008876646\r\n
Content-Disposition: form-data; name=\"image\"; filename=\"1.png\"\r\nContent-Type: image/png
\r\n\r\n\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\xaeB`\x82\r\n
-----------------------------189075738616438618431008876646--\r\n"
#2

Workaround for now (it is working at least in my demo app):

import HTTP, HTTP.Parsers
"""
  returns embedded data or nothing
"""
function parse_multipart(data::Vector{UInt8})
    chunk_end = HTTP.Parsers.find_end_of_chunk_size(data)
    if chunk_end == 0
        return nothing
    end

    boundary = data[1:chunk_end - 2] # should be without \r\n
    header_end = HTTP.Parsers.find_end_of_header(data)

    data_start = header_end + 1
    data_end = length(data) - chunk_end - 2
    # check that block ending is with same boundary + two additional hyphens
    if (data[data_end + 1: end] == [boundary..., 0x2d, 0x2d, 0x0d, 0x0a])
       return data[data_start : data_end]
    end

    return nothing
end

...
data = parse_multipart(c.conn.request.body)

Looks like there is a pull request with similar function but still not merged into HTTP - https://github.com/JuliaWeb/HTTP.jl/pull/264