# Extract binary file from HTTP request body

**URL:** https://discourse.julialang.org/t/extract-binary-file-from-http-request-body/96322
**Category:** Web Stack
**Tags:** http, oxygenjl
**Created:** [March 19, 2023, 10:15pm UTC](https://discourse.julialang.org/t/extract-binary-file-from-http-request-body/96322 "2023-03-19T22:15:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sschmidhuber](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sschmidhuber/32/13349_2.png) [@sschmidhuber](https://discourse.julialang.org/u/sschmidhuber)
#### Post date: [March 19, 2023, 10:15pm UTC](https://discourse.julialang.org/t/extract-binary-file-from-http-request-body/96322/1 "2023-03-19T22:15:10Z")

</div>

Hello,  
I’m struggling currently with extracting a binary file from a POST request body.  
On the client side I submit a form with a binary file and the enctype=“multipart/form-data”, that seems to work well.

On the server I’m using Oxygen.jl and try to store the binary content into a new file:

```julia
@post "/file" function(req)
    open(joinpath("..", "data", "filename"),"w") do f
        write(f, req.body)
    end
    return "file uploaded"
end

```

When I check the file with a Hex editor I see that there are additional bytes before and after the actual file, in my case an image, like multipart-boundry, filename, content-type,…

But `req.body` is a `Vector{UInt8}`, what is the best practice to extract the payload only? Maybe I’m approaching this problem from the wrong side, but I can’t wrap my head around it. 😵‍💫

Thank you for your help!

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [March 20, 2023, 4:45pm UTC](https://discourse.julialang.org/t/extract-binary-file-from-http-request-body/96322/2 "2023-03-20T16:45:30Z")

</div>

I think you need to parse the form out of the body as described in [this](https://discourse.julialang.org/t/parsing-multipart-data-using-http-jl/55540) thread.

---

<div class="post-metadata">

### Author: ![sschmidhuber](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sschmidhuber/32/13349_2.png) [@sschmidhuber](https://discourse.julialang.org/u/sschmidhuber)
#### Post date: [March 20, 2023, 10:14pm UTC](https://discourse.julialang.org/t/extract-binary-file-from-http-request-body/96322/3 "2023-03-20T22:14:20Z")

</div>

Thank you @contradict,  
indeed that is how to do it. In summary I’m able to get the following out of the multipart request array after parsing it, looking at the first element:

```julia
    content = HTTP.parse_multipart_form(req)
    content[1].filename
    content[1].contenttype
    content[1].data

```

The data field is exactly the binary file I was trying to get.
