#Upload File via Server Event Handler

9 messages · Page 1 of 1 (latest)

vapid mesa
#

I want to upload a file via server event handler but seems like that this is not working? My external API throws me 413 payload to large but outside of nuxt it works fine without any issues. What did I wrong? Here is my code:

// CLIENT SIDE
const formData = new FormData();
formData.append("file", file);

const res = await $fetch(`/api/storage/upload`, {
        method: "post",
        body: formData,
        headers: {
          "Content-Type": "multipart/form-data",
        }
});

// SERVER SIDE /api/storage/upload
export default defineEventHandler(async (event) => {
  const client = myExternalClientAPI(event);
  const data = await readBody(event) // should contain form data 
  const res = await client.storage.uploadImage(data); // throws me a 413 payload to large but works outside of nuxt3
  return res;
});
dense wagon
#

Hey Onur,
I got the same problem. Do you got a solution?

livid palm
#

Hey guys I have the same problem, do you have some news about it?

scarlet basalt
#

Hello. You can use await readMultipartForm Data(event) to get access to the file sent in the request body. This is also a function that comes from the H3

#

@livid palm

#

@dense wagon

livid palm
#

i receive undefined in server side

scarlet basalt
#

Strange. Can you send the client and server side code?

#

br?