sindresorhus/got

`electron.net` breaks multipart uploading

sindresorhus opened this issue · 4 comments

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.

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

Looks like I was seeing it too, damn #397

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 👍

@sonicdoe Great! Thanks for testing.