How to Configure AWS S3 in Strapi to Upload Different Files to Different Folders in the S3 Bucket

System Information
  • Strapi Version: 4.20.4
  • Operating System: MacOS
  • Database: MySQL
  • Node Version: v20.18.0
  • NPM Version: 6.14.18
  • Yarn Version: 3.6.4

I’m using Strapi with AWS S3 provider for media uploads. I want all my uploaded files to be able to be stored in a specific folder for example (images), (pdfs) and (videos) within my S3 bucket. I’ve tried using the rootPath but how do i try check for a file type and then according to the file type assign it to the appropriate folder in the config/plugins.js

upload: {
        config: {
            provider: "aws-s3",
            providerOptions: {
                accessKeyId: env("AWS_ACCESS_KEY_ID"),
                secretAccessKey: env("AWS_SECRET_ACCESS_KEY"),
                region: env("AWS_REGION"),
                params: {
                    ACL: env("AWS_ACL", "public-read"),
                    Bucket: env("AWS_BUCKET_NAME"),
                },
                customBucketPrefix: "images/",
            },
            actionOptions: {
                upload: {},
                delete: {},
            },
        },
    },