Closed rahulkumarsingh73690 closed 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; } }
Please read the documentation about handleUpload: https://hub.nuxt.com/docs/storage/blob#handleupload
handleUpload
You need to give the event as parameter, not the data from read body.
event
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.