Google-api-nodejs-client: Unable to upload more than 10MB

Created on 8 Feb 2018  Â·  11Comments  Â·  Source: googleapis/google-api-nodejs-client

When using the example code for uploading videos to youtube using the api (https://developers.google.com/youtube/v3/docs/videos/insert) i'm getting the following error for all videos over 10MB:

The API returned an error:  Error: Request body larger than maxBodyLength limit
    at RedirectableRequest.write (C:\Users\Malte\Googl…w-redirects\ind…:66)
    at PassThrough.ondata (_stream_readable.js:642)
    at emitOne (events.js:125)
    at PassThrough.emit (events.js:221)
    at addChunk (_stream_readable.js:265)
    at readableAddChunk (_stream_readable.js:252)
    at PassThrough.Readable.push (_stream_readable.js:209)
    at PassThrough.Transform.push (_stream_transform.js:146)
    at PassThrough.afterTransform (_stream_transform.js:87)
    at PassThrough._transform (_stream_passthrough.js:42)

~I was able to fix this by editing https://github.com/olalonde/follow-redirects/blob/master/index.js#L226 of the follow-redirects module to something bigger as this is stopping all bigger requestbodys and therefor stop the uploading of most videos.~

Edit: A better way to fix this is to install Version 1.2.6 of follow-redirect as this is the newest version without this new "feature".

See also this commit that implemented this restriction to follow-redirects https://github.com/olalonde/follow-redirects/commit/847a47fb00ea2dcb7a8886ca16d9d82dc6accb5d

Most helpful comment

Thank you @JustinBeckwith for fixing this by raising the default of maxContentLength in #1016 !

In the meantime for anyone else waiting for this fix to land in a release, the workaround that @condorman proposed above works a treat. Or if you'd prefer:

google.options({ maxContentLength: (100 * 1024 * 1024) });

All 11 comments

I'm having the same issue uploading a file to google drive, is there a way to override that setting from this library?

Another way to prevent this issue from happening is to install Version 1.2.6 of follow-redirect as this is the newest version without this new "feature".

@Lergin thanks, that worked

I'm also seeing this issue.

I resolve with "maxContentLength"

const youtube = google.youtube({ version: 'v3', auth: client, maxContentLength: 100 * 1024 * 1024})

Thank you @JustinBeckwith for fixing this by raising the default of maxContentLength in #1016 !

In the meantime for anyone else waiting for this fix to land in a release, the workaround that @condorman proposed above works a treat. Or if you'd prefer:

google.options({ maxContentLength: (100 * 1024 * 1024) });

Perhaps this should be somewhere in the docs. Perhaps add google.options({ maxContentLength: (100 * 1024 * 1024) }); to the Youtube video upload sample, as videos files tend to be quite big.

This no longer an issue, as we've swapped out axios for gaxios. Gaxios does not set a default upper bound for maxContentLength :)

Hmm, that may make sense, because yesterday when I tried to upload a 3GB video file via node.js to YouTube, it still threw a maxContentLength error, despite me using:

const service = google.youtube({
    version: `v3`,
    maxContentLength: 100 * 1024 * 1024
});

Explain why this can happen? Part of error trace:

Error: Request body larger than maxBodyLength limit
    at RedirectableRequest.write (D:\...\node_modules\follow-redirects\index.js:105:24)
    at PassThrough.ondata (_stream_readable.js:639:20)
    at emitOne (events.js:116:13)
    at PassThrough.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at PassThrough.Readable.push (_stream_readable.js:208:10)
    at PassThrough.Transform.push (_stream_transform.js:147:32)
    at PassThrough.afterTransform (_stream_transform.js:88:10)
    at PassThrough._transform (_stream_passthrough.js:42:3)
  config: 

PM/email me if you need entire error trace + config, or even my source code.

We haven't shipped the code that's on master just yet. This will be in the v37 release :)

Yeah, so far it seems to be working! Looks like I'm currently uploading a 2.5h 9gb video via googleapis.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raapperez picture raapperez  Â·  3Comments

leecheve picture leecheve  Â·  3Comments

rainabba picture rainabba  Â·  4Comments

lowagner picture lowagner  Â·  3Comments

Chethandsagar picture Chethandsagar  Â·  4Comments