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

橙三吉。 提交于 2021-01-21 12:59:31

问题


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?


回答1:


You are setting

'maxContentLength': Infinity,
'maxBodyLength': Infinity

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




回答2:


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()}
})


来源:https://stackoverflow.com/questions/56868023/error-request-body-larger-than-maxbodylength-limit-when-sending-base64-post-req

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!