Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Upload to HTTP Server with Multipart Form #1590

Closed
jacob-pro opened this issue Sep 27, 2020 · 5 comments
Closed

File Upload to HTTP Server with Multipart Form #1590

jacob-pro opened this issue Sep 27, 2020 · 5 comments
Labels

Comments

@jacob-pro
Copy link

Question

I can see there is an example of file uploads however I am not sure how I upload a file to a HTTP server in a multipart form?

In the JS world I would send a FormData body (I'm assuming that browsers would then typically stream the file data from disk when performing the HTTP request).

As far as I can understand see the FetchService requires the body to be Into<Format<DATA>> which would prevent any sort of streamed / chunked HTTP request?

I realise for small files I can just read the file into memory using the ReaderService but then I am not sure how / what library I can use to create a multipart form containing this, that I can add to a FetchService::fetch?

@teymour-aldridge
Copy link
Contributor

Any browser-defined Javascript functions will map 1-to-1 to some mechanism inside the web_sys crate, so you can just think about how you would do it in Javascript and search web_sys's documentation for the appropriate items. If you need to use async code this solution is quite neat.
(not a total answer, but I hope this helps somewhat)

@jacob-pro
Copy link
Author

Yeah thanks, I realise its possible to do by calling the appropriate Javascript functions directly, but I was already using the Yew Fetch API for all my other API routes.
I currently only need to upload small files (just a photo upload) so I'm just reading them into memory and encoding them into a multipart myself.
(https://github.com/kiwi-joinery/kiwi-admin/blob/master/src/api/gallery.rs#L87)

@teymour-aldridge
Copy link
Contributor

I'll try and work out how to handle larger files (file uploads are not something I'm particularly experienced with) and add it to the documentation!

@jacob-pro
Copy link
Author

There is actually an issue open for this already
#1190

@teymour-aldridge
Copy link
Contributor

Cool – I guess we can close this one and keep only that one then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants