Is it possible to do a PUT request with multipart form data?
With Superagent I would expect the following to work, but it doesn't.
var request = Request
.put("http://localhost:8080/upload_file")
.field("name", file.name)
.field("size", file.size)
.attach("file", file.file, file.file.name)
.accept("application/json")
If I do a post, it works. The difference is the Content-Type. With the successful post request the Content-Type is multipart/form-data; boundary=------WebKitFormBoundaryXg34NkBFcYWq60mH.
If I were to set this manually how would I know what the boundary should be? It seems to be automatically generated by Superagent.
You should probably do a POST, per Tum's comment.
If I were to set this manually how would I know what the boundary should be? It seems to be automatically generated by Superagent.
You should let Superagent manage that by itself - don't try to set the type yourself, leave off the type call and it will include the correct boundary identifier when it sets it as multi-part itself.
No, it is not possible to do a PUT request with content-type multipart/form-data due to an underlying limitation in PHP as discussed here: https://bugs.php.net/bug.php?id=55815
You might want to take a look at a 'hack' that was done for Symfony in Chekote/symfony: https://github.com/Chekote/symfony/commit/dc1279b2e4c0e9cbcb5b7d578891c31dd878b43b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With