question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

source.on is not a function

See original GitHub issue
const request = require('request-promise');
const req = require('request')
const fs = require('fs');
const FormData = require('form-data')

function readImage(){
    return new Promise(function(resolve, reject) {
        fs.readFile('./img/150150.gif', (err, data) => {
            if(err) reject(err);
            resolve(data);
        });
    });
}

readImage().then(data => {
    let dat = toArrayBuffer(data);
    let filename = new Date().getTime();
    let formData = new FormData();
    formData.append('imageClass', 'twitterApp');
    formData.append('X-Requested-With', 'Iframe')
    formData.append('X-HTTP-Accept', 'application/json, text/javascript, */*; q=0.01')
    formData.append('file', dat, "twitterLogo");
    request.post({url: 'example.com/api/images/', data: dat, processData: false, contentType: false, type: 'POST'}).then(data => {
        console.log(data)
    }).catch(err =>{
        console.log(err);
    })
}).catch(error => {
    console.log(error);
})


function toArrayBuffer(buf) {
    var ab = new ArrayBuffer(buf.length);
    var view = new Uint8Array(ab);
    for (var i = 0; i < buf.length; ++i) {
        view[i] = buf[i];
    }
    return ab;
}

request.post says that source.on is not a function, though, I have no idea why that’d be. This is attempting to send an image file.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

33reactions
ketantadacommented, Mar 21, 2018

I am getting error: TypeError: source.on is not a function at Function.DelayedStream.create (/node_modules/delayed-stream/lib/delayed_stream.js:33:10) at FormData.CombinedStream.append (/node_modules/combined-stream/lib/combined_stream.js:44:37) at FormData.append (/node_modules/form-data/lib/form_data.js:74:3) at appendFormValue (/node_modules/request/request.js:323:21) at Request.init (/node_modules/request/request.js:334:11) at new Request (/node_modules/request/request.js:128:8) at request (/node_modules/request/index.js:53:10) My code is:

var options = {
  url: 'http://...',
  method: 'POST',
  formData: {
    file: fs.createReadStream(__dirname + '/file.jpg'),
    first_name: 'first_name'
  }
}
request(options, function() {})

Request Version: request@2.85.0 node version: node v9.8.0

2reactions
nmccreadycommented, Aug 16, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: source.on is not a function · Issue #2366 - GitHub
I'm trying to POST an array of values to a HTTP endpoint, and this is the error I receive: TypeError: source.on is not...
Read more >
Getting ERROR: uncaughtException: source.on is not a ...
When you call createFormData with myJson as parameter, you will see exception source.on is not a function ! And we keep thinking where...
Read more >
Error Received: Source.on is not a function - App Platform
Hello Team, I am trying to create a ticket in Freshdesk along with attachments, but I am getting an error. The Error is:...
Read more >
"source.on is not a function" for discord.js - Questions - n8n
I figured out how to pass the parameters on to the content, but now I am having the issue of a function being...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found