How to create /uploads-Directory on startup?

System Information
  • Strapi Version: 4.3.0

In v3 we created the /uploads-directory (as a fallback-solution) in bootstrap.js.
However now with v4 strapi seems to not even reach the new index.js if the /uploads-directory is missing.

Is there any advice how we should create the /uploads-directory? Is there an entry-point for us before index.js?

Should be able to use bootstrap.js
and then do


const {mkdir, access,} = require('fs/promises')
const { constants } = require(`fs`);

const createFolder = async() => {
try {
await access(`${process.cwd()}/public/uploads`, constants.R_OK);
console.log("Folder exists")
} catch(error) {
await mkdir(`${process.cwd()}/public/uploads`)}
console.log("Created directory")
}
}

think you need to check with the process where it's run from etc, else it will run it from the wrong place.

Better solution would be to make a `public/uploads` folder and inside of it just add `.gitkeep` so it gets committed that way you don't need to make it.

Make sure you don't do this in Docker as there is no point then rather, you then want to use bind the folder etc else it would be deleted on removal of the container.