0

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:

enter image description here

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.

LondonGuy
  • 10,778
  • 11
  • 79
  • 151

1 Answers1

0

These settings worked for me:

    options: {
        payload: {
            maxBytes: 10485760,
            parse: true,
            output: 'stream',
            allow: ['multipart/form-data'],
            multipart: true
        }
    }

Also, I had to switch to Insomnia for testing because Postman gives me a bad-request error for some reason. I remember experiencing something like this in the past.

LondonGuy
  • 10,778
  • 11
  • 79
  • 151