Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Request body larger than maxBodyLength limit when sending base64 post request Axios

Tags:

node.js

axios

When sending a post request with a Base64 encoded pdf as the body i recieve the error

Error: Request body larger than maxBodyLength limit

I have tried setting both of the following

'maxContentLength': Infinity, 'maxBodyLength': Infinity

in the request config

const result = await axios({
            url: `the url`,
            headers: {'Authorization': `Bearer ${auth_token}`, 'Content-Type': 'application/json'},
            method: 'post',
            data: {
                'ParentId': record_id,
                'Name': file_name,
                'body': body,
                'Description': description ? description : "",
                'maxContentLength': Infinity,
                'maxBodyLength': Infinity
            }
        });

Does anyone have a workaround?

like image 859
user1781563 Avatar asked Jul 03 '19 10:07

user1781563


2 Answers

You are setting

'maxContentLength': Infinity,
'maxBodyLength': Infinity

In your data object. It should be inside the config object, outside the data object.

like image 194
Aritra Chakraborty Avatar answered Oct 17 '22 20:10

Aritra Chakraborty


That is what worked for me:

axios({
    method: 'post',
    url: posturl,
    data: formData,
    maxContentLength: Infinity,
    maxBodyLength: Infinity,
    headers: {'Content-Type': 'multipart/form-data;boundary=' + formData.getBoundary()}
})
like image 44
Sumith Ekanayake Avatar answered Oct 17 '22 19:10

Sumith Ekanayake