transloadit/node-sdk

Unable to pass `request` upload

Closed this issue · 7 comments

If you set { upload: { file: request('some-url') } } (with the request library), then this error happens:

/home/julian/dev/transloadit/node-sdk/node_modules/into-stream/index.js:74
		const chunk = input.slice(0, size);
		                    ^

TypeError: input.slice is not a function
    at Class.reader [as _from] (/home/julian/dev/transloadit/node-sdk/node_modules/into-stream/index.js:74:23)
    at Class._read (/home/julian/dev/transloadit/node-sdk/node_modules/from2/index.js:68:10)
    at Class.Readable.read (/home/julian/dev/transloadit/node-sdk/node_modules/readable-stream/lib/_stream_readable.js:443:10)
    at resume_ (/home/julian/dev/transloadit/node-sdk/node_modules/readable-stream/lib/_stream_readable.js:790:12)

It works if the request stream is piped to a simple PassThrough, and that then passed to the sdk

mifi commented

Ohh it’s not ‘upload’ but ‘uploads’. We could add some validation of the json document.

mifi commented

See example here: (it’s got, not request tho)

it('should allow adding different types', async () => {

Sorry that was a typo, I'm indeed passing uploads. I assume this is something specific to the request library

mifi commented

Ohh ok i will look into that. I guess we should have a unit test for request also since many ppl are using that too

It has long been deprecated so personally I don't think we need to support it really, but it would be nice to have a different error

mifi commented

Seems like is-stream does not detect this stream as readable because it's an old type of stream (sindresorhus/is-stream#9)
Could be fixed by just checking for isStream instead of also checking for readable, but since request is deprecated and it can be worked around with passthrough, then I will instead throw a better error