Reputation: 755
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?
Upvotes: 52
Views: 53918
Reputation: 810
If you want to set the maxContentLength and maxBodyLength only one time for all axios calls you can register an interceptor. Add this code before all your axios calls and you body size problems are gone.
axios.interceptors.request.use(request => {
request.maxContentLength = Infinity;
request.maxBodyLength = Infinity;
return request;
})
Upvotes: 7
Reputation: 2265
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()}
})
Upvotes: 53
Reputation: 12542
You are setting
'maxContentLength': Infinity,
'maxBodyLength': Infinity
In your data object. It should be inside the config object, outside the data object.
Upvotes: 79