Skip to content

electron.net breaks multipart uploading #315

@sindresorhus

Description

@sindresorhus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething does not work as it shouldexternalThe issue related to an external project

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions