Search code examples
strapi

Issue with Image Upload Function with Strapi v4


I’m currently trying to implement the image upload feature, following this guide:

But here I’ve encountered a problem.

enter image description here

Could someone explain to me how I have to program here? The default folder ‘public/uploads’ is there, so why does it still ask for ‘tmpWorkingDirectory’? Is there an example for this?

  • Strapi Version: 4.21.1
  • Operating System: Heroku
  • Database: PostgreSQL
  • Node Version: 18.20.0
  • NPM Version: >=6.0.0

Solution

  • You are trying to upload files on Heroku with the default file provider. It means that you are trying to upload file on the Heroku instance. This is not possible.

    More information here on why: https://devcenter.heroku.com/articles/active-storage-on-heroku

    "Heroku has an “ephemeral” hard drive, this means that you can write files to disk"

    You will have to setup an AWS3 bucket or use another Upload provider to host your assets.

    That's why you have an error. And the error comes from this function: https://github.com/strapi/strapi/blob/develop/packages/core/upload/server/services/upload.js#L50