-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
fetch does not support posting files as multipart/form-data #9684
Comments
Amend to the above - Using Blobs does send data (and the filename parameter is honoured). But it's incorrectly represented (sent as a stream of ascii byte values with no separators, rather than a binary stream) |
@ProPuke I encounter the same problem. |
@tguillemot Yeah, I ended up doing it using node and const fs = require('fs');
const request = require('request').defaults({jar: true});
const {remote} = require('electron');
const {dialog} = remote; request.post({
url: url,
formData: {
file: fs.createReadStream(filename)
}
}, (err, res, body) => {
if(err){
dialog.showErrorBox('Error uploading file', `Something went wrong (${res.statusCode})`);
return;
}
// hande body...
}) I prompt the user for the file with dialog.showOpenDialog(remote.getCurrentWindow(), options, callback); then in (as you can see I did it in the renderer, making use of remote, but might be neater to do it in main via an ipc event) The downside to using node instead of the renderer, is that this transfer won't show in the dev tools under network; So you're working a bit more blind. |
Thanks for your solution @ProPuke. For the record, I have used an input type file instead of the |
We are no longer implementing bugfixes for versions of Electron <= |
@MarshallOfSound I hate to want to re-open this, but I'm still hoping that I had been using the npm When I try building the
I get the Response
When I setup the same POST multipart/form via the Insomnia rest client, the request and headers looks like:
| (16 KB hidden)
< HTTP/1.1 200 OK
With
But after merging to
|
@MarshallOfSound can you please re-open this ? This still happens in electron 6 |
FormData is not defined in electron v31 alpha |
Expected behavior
Amending a file to a FormData instance and then POSTing it with fetch from the renderer should include the file contents as multipart/form-data
Actual behavior
The
file
parameter is passed with no value and the filename parameter is ignored.Using a Blob instead of a fs.ReadStream, the filename parameter is honoured and data sent, but unfortunately incorrect data is sent.
How to reproduce
Check the network tab in Developer Tools and verify there is no filename or data on the request data
The text was updated successfully, but these errors were encountered: