Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images cannot be parsed when obtained through event handlers #1329

Open
GalacticHypernova opened this issue Apr 17, 2024 · 0 comments
Open

Comments

@GalacticHypernova
Copy link

Currently Nuxt/Image only seems to work fine with images that are presented at build time in ~/public. While that may suffice most static sites, for sites that require user interaction, including uploading media, this ends up breaking the images in production. It is not ideal to have to rebuild the app every time an image is uploaded, for quite obvious reasons.
Take for example this code:

// ~/server/routes/images/[image].get.ts
export default defineEventHandler({
    handler: async (event) => {
        const img = getRouterParam(event, "image")
        const imageStorage = useStorage("images") // this could, for example, be an FS driver configured in `nuxt.config.ts`
        if (await imageStorage.hasItem(img)) {
            return await imageStorage.getItem(img)
        }
    }
})

This works fine when going to it on the browser, but Nuxt/Image fails to parse this when used in a element, with a message stating the file cannot be found.

It would be very beneficial to have the benefits of image optimization for images that are obtained dynamically through event handlers, as most SSR apps use this kind of functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant