Upload my file from custom controller

System Information
  • Strapi Version: 4.17
  • Operating System: Mac OS X
  • Database: Postgres
  • Node Version: 16.15
  • NPM Version: 8.5.5
  • Yarn Version: N/A

I am not able to upload an entity-linked file from a custom controller. When I execute the code, the Media Library page goes offline and I have to manually delete the entry from the Files table in the DB. What am I doing wrong? See my code below.

        const content = await strapi.db.query('api::content.content').create({
            data: {
                myfield: ctx.query.myfield
            },
            files: ctx.request.files
        });

Hi, did you found any solution to that problem ? I don’t know where Strapi hide documentation about manipulating file within a controller nor plugin :frowning:

try this

const content = await strapi.db.query('api::content.content').create({
            data: {
                myfield: ctx.query.myfield
            },
            files: {
                myMediaFiledName: ctx.request.files[ 'files.mediaName' ] 
                     }
        });