nuxt-hub / starter

Full-stack application running on Cloudflare Pages, with zero configuration. Support D1, R2 and KV storages.
102 stars 8 forks source link

ImageGallery's useUpload throws 'Missing files' #5

Closed kevcjones closed 1 month ago

kevcjones commented 2 months ago

Expected To upload an image and see it persist as the code suggests it should

Experienced useUpload.js thows 'Missing files'

Cause This error thrown from useUpload.js when data.length is undefined.

if (!data || !data.length) { 
            throw createError({
                statusCode: 400,
                message: "Missing files"
            });
        }

Reason Current starter example passing in the input from the form form.image which does not have 'length'

Solution My personal solution was to follow the example more closely from the linked https://hub.nuxt.com/docs/storage/blob#useupload but even that didn't work out of the box.

Fix

await upload([...form.image.files])

Seems to do the trick

atinux commented 1 month ago

Tested and working now