strapi-community / strapi-plugin-local-image-sharp

Dynamically resize, format and optimize images based on url modifiers.
https://strapi-community.github.io/strapi-plugin-local-image-sharp/
65 stars 17 forks source link

[BUG]: IPX error when trying to access any media #17

Closed fabio-nettis closed 1 year ago

fabio-nettis commented 1 year ago

Description

After upgrading to the newest version I am no longer able to access any imagery via the its url. Following console output is shown when any file is accessed via /uploads/filename.ext

IPX Error (File not found (/Users/fabio_nettis/github/bucan-labs/application/api/public/uploads/organization/banner/ekz_hauptsitz_d1d858b79b.jpg))
IPXError: File not found (/Users/fabio_nettis/github/bucan-labs/application/api/public/uploads/organization/banner/ekz_hauptsitz_d1d858b79b.jpg)
    at createError (/Users/fabio_nettis/github/bucan-labs/application/api/node_modules/ipx/dist/shared/ipx.eadce322.cjs:76:15)
    at Object.filesystem (/Users/fabio_nettis/github/bucan-labs/application/api/node_modules/ipx/dist/shared/ipx.eadce322.cjs:94:15)
    at async ipxMiddleware (/Users/fabio_nettis/github/bucan-labs/application/api/node_modules/strapi-plugin-local-image-sharp/src/middleware.js:89:19) {
  statusMessage: 'IPX: File not found',
  statusCode: 404
}

According to this forum post following line in the plugins code is causing the above error, might be worth looking into.

const ipx = createIPX({
  dir: `${strapi.dirs?.dist?.public ?? strapi.dirs?.public}/uploads`,
})

// [Possible fix]: The variable strapi.dirs.public is undefined and I just added an ?? “public” and it works.
const ipx = createIPX({
  dir: `${strapi.dirs?.dist?.public ?? strapi.dirs?.public ?? "public"}/uploads`,
})

Steps to reproduce

  1. Install latest version of the plugin
  2. Upload some media to local provider
  3. Try to access uploaded media via the created url

Expected behaviour

Obviously the media should be accessible through the url if present in the directory.

Environment

Additional context

N/A

fabio-nettis commented 1 year ago

The above code snippet seems to be from an older version of the plugin so never mind. I've gone ahead and created a PR to fix this issue.