I'm trying to test an single image uploads for my Hapi JS api. When I try to access the file
property in the payload object, I get an undefined
message.
This is my route handler:
server.route({
method: 'POST',
path: '/profile/upload-image',
handler: async (request, h) => {
let data = request.payload;
console.log(data.file);
return h.response(request.payload);
},
options: {
auth: false,
payload: {
output: 'stream',
parse: false,
//multipart: true,
maxBytes: 1024 * 1024 * 100
}
}
});
This is the response shown in postman:
I tried in Insomnia aswell, just to be sure it wasn't an issue with Postman; I get the same result.
What could be wrong here?
I tried setting: allow: 'multipart/form-data'
but this didn't work. I also tried a few different combinations e.g. parse: true
and increasing the maxBytes, but this didn't work either.