request: TypeError: source.on is not a function
return rp.post({
url: uri("collections/people"),
formData: [{a: 1}, {a: 2}],
});
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 a function
at Function.DelayedStream.create (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/delayed-stream/lib/delayed_stream.js:33:10)
at FormData.CombinedStream.append (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/combined-stream/lib/combined_stream.js:43:37)
at FormData.append (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/form-data/lib/form_data.js:68:3)
at appendFormValue (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/request/request.js:328:21)
at Request.init (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/request/request.js:339:11)
at Request.RP$initInterceptor [as init] (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/request-promise-core/configure/request2.js:45:29)
at new Request (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/request/request.js:129:8)
at request (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/request/index.js:55:10)
at Function.post (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/request/index.js:63:12)
at /home/kuba/projects/sealcode/sealious/integration-tests/test.js:45:13
at tryCatcher (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/promise.js:504:31)
at Promise._settlePromise (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/promise.js:561:18)
at Promise._settlePromise0 (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/promise.js:606:10)
at Promise._settlePromises (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/promise.js:685:18)
at Async._drainQueue (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/async.js:148:10)
at Immediate.Async.drainQueues [as _onImmediate] (/home/kuba/projects/sealcode/sealious/integration-tests/node_modules/bluebird/js/release/async.js:17:14)
at tryOnImmediate (timers.js:543:15)
at processImmediate [as _immediateCallback] (timers.js:523:5)
Are arrays not allowed in formData?
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 13
- Comments: 17
Commits related to this issue
- companion: avoid bad mutation of file object see https://github.com/request/request/issues/2366#issuecomment-400646265 fixes #1581 — committed to transloadit/uppy by ifedapoolarewaju 5 years ago
formData accepts only three types of elements viz. string, Buffer and Stream, so try this:
@abhiCR7 Not everything. The rule is that values of formData object can only by any of these: string, Buffer, Stream. @VijayakumarManickam is right.
In my case I had to change:
to
I tried to post something like this
and got this error also
nope, formData has to be an object. ran into this problem myself 😃
I’ve stumbled upon the same issue and found an answer that worked for me here - https://github.com/request/request/issues/1495
Basically, you still need to send the formData as object, the difference is that you have to structure your formData object similar to the following…
As seen in the example. Instead of sending the name as an object with first and last property, the first and last were sent as if you are accessing an object like you would an array. Ex: name[first] vs. name.first
Note: Credits to @joshuamcginnis for the answer.
@ketantada are you cloning or modifying the options object in some other way in your code? The stream object can break due to that.
everything needs to be stringified inside formData. try:
return rp.post({ url: uri("collections/people"), formData: JSON.stringify({ 'subscriptions': [ { "subscription": subscriptionId, "quantity": newQty, "product": product, "prorate": true } ] }), });Just in case. It worked for me.
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:Request Version: request@2.85.0node version: node v9.8.0