nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
802 stars 35 forks source link

Why HTTP method is not allowed on hubBlob().handleUpload #178

Closed rahulkumarsingh73690 closed 1 week ago

rahulkumarsingh73690 commented 1 week ago

I am trying to upload the image and return the path of the image instantly via HTTP post request but I can't find anyway.

export default eventHandler(async (event) => {
  const { data } = await readBody(event);

  const result = await hubBlob().handleUpload(data, {
    multiple: false,
    maxSize: '8MB',
    types: ['image/png', 'image/jpeg']
  })
  const resultData = result[0]
  return {
    body: { pathname: resultData.pathname }
  };
})
async function uploadImage(e: Event) {
  // if (isSubmitted.value) return;

  // isSubmitted.value = true;

  try {
    console.log(e)
    const responseData = await $fetch('/api/images/upload', {
      method: 'POST',
      body: {
        data: e
      }
    });

    console.log(responseData)

    // if (responseData.status === 200) {

    // } else {
    //   throw new Error;
    // }
  } catch (error) {
    console.error(error);

  } finally {
    // isSubmitted.value = false;
  }
}
Atinux commented 1 week ago

Please read the documentation about handleUpload: https://hub.nuxt.com/docs/storage/blob#handleupload

You need to give the event as parameter, not the data from read body.