Replies: 4 comments 11 replies
-
I have the same error. Did you manage to find a fix? |
Beta Was this translation helpful? Give feedback.
-
My project has same logic, client uploads a file which is sent to NextJS API under pages/api/upload then it gets the data from res.body like yours. But there is a problem, first i sent a file directly on client and then using /api/upload. I compared the files in hexedecimal form and it differs. I think NextApiRequest brokes the encoding. For example hex 0x89 turned into 0xEFBFBD. I really need to solve this issue... |
Beta Was this translation helpful? Give feedback.
-
you can also just pass the initial request ... no need of installing other packages ... just need to correct the headers import Repository, { apiUrl } from "~/repositories/Repository";
import { parse } from 'cookie';
export const config = {
api: {
bodyParser: false
}
}
export default async (req, res) => {
const { headers: { cookie, ...rest }, method } = req;
const { auth } = parse(cookie);
if (method === 'PUT') {
const headers = {
Authorization: `Bearer ${auth}`,
'content-type': rest['content-type'],
'content-length': rest['content-length']
}
return Repository.put(`${apiUrl}/user/me/files`, req, { headers: headers })
.then(response => {
const { data } = response;
return res.status(200).json(data);
})
.catch(error => {
const { response: { status, data } } = error;
return res.status(status).json(data);
})
}
else
return res.status(405);
} |
Beta Was this translation helpful? Give feedback.
-
Hi there, Here's one more good solution w/o using any external packages.
|
Beta Was this translation helpful? Give feedback.
-
So here it is. been bashing my head all day on this one.
I have a web app with next using the local api.
Then i'm calling my external api :
Beta Was this translation helpful? Give feedback.
All reactions