Is it possible to set a Media Attribute manually?

System Information
  • Strapi Version: 3.4.1
  • Operating System: Win64x
  • Database: SQLLite
  • Node Version: 14.11.0
  • NPM Version: 6.14.8
  • Yarn Version: 1.22.5

Hi there

Is it possible to set a Media (Image) Attribute within the beforeCreate/afterCreate lifecycle hook ? in my case a qrcode should be generated and the image (SVG) should be uploaded.

Hi Phil,
What I would do is rather than uploading an Image, change the Media field to JSON, and upload the SVG there instead.
Generating the qrcode on your front end and convert it to svg there.
here is a github link that might be of use to you: GitHub - papnkukn/qrcode-svg: A simple QR Code generator in pure JavaScript / node.js library

1 Like

You can also use this plugin (v4 only).