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

electron.net breaks multipart uploading #315

Closed
sindresorhus opened this issue May 26, 2017 · 4 comments
Closed

electron.net breaks multipart uploading #315

sindresorhus opened this issue May 26, 2017 · 4 comments
Labels
bug Something does not work as it should external The issue related to an external project

Comments

@sindresorhus
Copy link
Owner

I wasted a lot of time debugging and turned out in the end to be because of electron.net. I should have known better than to trust when documentation says it's compatible...

Latest master of Got.

// x.js
'use strict';
const fs = require('fs');
const electron = require('electron');
const got = require('got');
const FormData = require('form-data');

const endpoint = 'https://upload.giphy.com/v1/gifs';

const form = new FormData();
form.append('api_key', 'dc6zaTOxFJmzC');
form.append('file', fs.createReadStream(process.argv[2]));

electron.app.on('ready', () => {
	got.post(endpoint, {body: form, useElectronNet: false})
		.then(x => {
			console.log(x.body)
		})
		.catch(console.error);
});
❯ electron x.js somgif.gif
{ HTTPError: Response code 401 (Unauthorized)
    at stream.catch.then.data (/Users/sindresorhus/dev/oss/got/index.js:176:13)
    at process._tickCallback (internal/process/next_tick.js:103:7)
  name: 'HTTPError',
  host: 'upload.giphy.com',
  hostname: 'upload.giphy.com',
  method: 'POST',
  path: '/v1/gifs',
  protocol: 'https:',
  url: 'https://upload.giphy.com/v1/gifs',
  statusCode: 401,
  statusMessage: 'Unauthorized',
  headers:
   { connection: [ 'keep-alive' ],
     'content-length': [ '120' ],
     'content-type': [ 'application/json' ],
     date: [ 'Fri, 26 May 2017 06:57:47 GMT' ],
     server: [ 'nginx/1.8.0' ],
     'x-robots-tag': [ 'noindex' ] } }

But if I set {useElectronNet: false} option it works:

{"data":{"id":"xUPGcpzBUNI6LfbgeA"},"meta":{"status":200,"msg":"OK","response_id":"5927d27a70f352831c34e527"}}

I could use some help debugging where exactly it breaks so we can report it to Electron.

@sindresorhus sindresorhus added bug Something does not work as it should ✭ help wanted ✭ labels May 26, 2017
@marwenlandoulsi
Copy link

hi @sindresorhus
did you find any solution. i have the same issue :(

sindresorhus added a commit that referenced this issue Oct 3, 2017
Fixes #359
Related to #315

`electron.net` is just too buggy.
@framerate
Copy link

Looks like I was seeing it too, damn #397

@sonicdoe
Copy link
Contributor

As mentioned by @brandon93s in #397 (comment), this should be working now. I’ve tried the example in the original post with got v8.3.2 and Electron v2.0.4 and it worked 👍

@sindresorhus
Copy link
Owner Author

@sonicdoe Great! Thanks for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should external The issue related to an external project
Projects
None yet
Development

No branches or pull requests

4 participants