For handling uploading request from web client (using XMLHttpRequest)

Hi, I’m on handling a Phoenix web server. We’re developing an API for uploading from a web client - which uses XMLHttpRequest for uploading video.

When receiving {conn, params} I don’t see anything in params, also don’t know how to extract the video data from the request.

Anyone can give me a hint on how to work on this? A link to a tutorial is gonna be highly appreciated.

Thanks a lot

See this paragraph in the docs:

Because the request body can be of any size, reading the body will only work once, as Plug will not cache the result of these operations. If you need to access the body multiple times, it is your responsibility to store it. Finally keep in mind some plugs like Plug.Parsers may read the body, so the body may be unavailable after being accessed by such plugs.

What parsers are you using in your Phoenix endpoint? How exactly do you do the upload from the client side?

1 Like

Hi Stefan,

The client site uses react and they have some mistakes in their code, they put params in the wrong place I guess. Somehow fetching the file for uploading is also wrong. Have no idea on the front end stuff.

Thanks so much for your reply,

Have you managed to solve the issue?

It’s already solved by the code changes on the client-side.

1 Like