Enable files to be set as value in `FormData`
It's quite strange to have FormData::get returning FormEntry with FormData::set and FormData::append accepting only &str. It would be great if we can insert File or something like it directly into FormData.
This is a great idea. Is this something you would like to work on?
I'd love to. But there seems to be some issues that should be resolved first:
-
Should we replace current
appendandsettoFile-aware variant or create a new one? Replacing them will be a breaking change. https://github.com/cloudflare/workers-rs/blob/07bf913c21e03558af8c092d5dc53ef148ad8ec7/worker/src/formdata.rs#L79-L89 -
In what way should we handle this
Fromimplementation? Specifically, can we return&dyn AsRef<&str>fromFile? https://github.com/cloudflare/workers-rs/blob/07bf913c21e03558af8c092d5dc53ef148ad8ec7/worker/src/formdata.rs#L103-L112
I just ran into this issue after creating most of my project and I've been in disbelief that this isn't available. Using a worker as a switchboard to send and receive files just makes sense to me; the functionality as a service is severely limited without this.
@sfbr As a workaround, you can manually build a FormData body and set appropriate headers to send multipart data. crate multipart will do this for you.
@kiwiyou Are you suggesting to send the request using that crate or to create the byte array and use it with this API? Additionally, I don't see where I would send FormData even if I did create it.
Sorry for late response. I meant creating a form data, encoding it into a byte array, and attaching it as a request body. FormData cannot be directly sent with current API as you said.