I am having a bit of trouble forwarding multipart/form-data using NextJS api.
async function proxy(req: NextApiRequest, res: NextApiResponse): Promise<void> {
const { body, headers, method, url } = req;
// Doing some work to handle authentication
const rewriteUrl = url?.replace('/api/proxy', '');
const config: AxiosRequestConfig = {
url: rewriteUrl,
method: method as Method,
headers: {
cookie: '',
Authorization: token,
},
data: body,
};
try {
const { data: originalData, status } = await axiosInstance(config);
return res.status(status).json(originalData);
} catch (err) {
return res.status(err.status).json(err);
}
}
export default proxy;
When calling the API directly or using non multipart/form-data network calls, no problem whatsoever. However, when proxying a multipart/form-data, I am receiving 413 Payload Too Large
I am have been trying to use
export const config = {
api: {
bodyParser: false,
},
};
but in that case the backend API is responding with 400 telling that the file doesn't exist.
As am I adding an authentication header before forwarding the request, can this be the culprit as the content size change?