Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the option maxBodyLength on putFileContents() #220

Merged
merged 2 commits into from
Oct 12, 2020
Merged

Allow setting the option maxBodyLength on putFileContents() #220

merged 2 commits into from
Oct 12, 2020

Conversation

bennigraf
Copy link
Contributor

@bennigraf bennigraf commented Oct 12, 2020

Hi there,

I recently ran into a problem when uploading big files to a nextcloud instance. Axios would complain

Error [ERR_FR_MAX_BODY_LENGTH_EXCEEDED]: Request body larger than maxBodyLength limit

This PR allows using the option maxBodyLength directly on the putFileContents method of this webdav client. One would use it for example like this:

await client.putFileContents(
  "/remote/file", 
  fs.readFileSync('./a-big-file'), 
  { 
    'maxBodyLength': Infinity,
  }
);

To achieve this, the option is simply passed through to axios which in turn will pass it on to follow-redirects, which is it's default backend in nodejs environments. It did in fact solve the issue in my project.

Until earlier this year, axios would have used the value of maxContentLength to set the value of maxBodyLength, but at some point someone found out that those two are in fact not the same and changed that behaviour, which I assume broke functionality of webdav-client as well. In my understanding, maxContentLength is now supposed to be used only for setting the limit of the respnse size, while maxBodyLength defines the limit of the request body size. See this issue for reference: axios/axios#2696

Let me know what you think!

Best,
Benjamin.

Document the `maxBodyLength` property on the `PutOptions` object. It will be passed through to `follow-redirects` in nodejs-environments, where it is the default axios backend.

See also those issues:
axios/axios#2696
axios/axios#1323

The option is documented here: https://www.npmjs.com/package/follow-redirects
Allow passing the option `maxBodyLength` through to axios which in turn will pass it on to `follow-redirects`, which is it's default backend in nodejs environments
@perry-mitchell
Copy link
Owner

perry-mitchell commented Oct 12, 2020

@bennigraf Have you tried with 3.5.0? Shouldn't this PR have fixed it? :)

Nevermind, did some research and can see it's for the request, whereas max-content-length is for the response.

@perry-mitchell perry-mitchell self-assigned this Oct 12, 2020
@perry-mitchell perry-mitchell merged commit 855a08a into perry-mitchell:master Oct 12, 2020
@bennigraf
Copy link
Contributor Author

Awesome, thanks for the quick approval and for releasing this directly!

And thanks alot for creating and maintaining this nice library. 🥇

@bennigraf bennigraf deleted the patch-1 branch October 25, 2020 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants