I haven’t got time right now to go through the code line by line but a couple of things stand out to me.
-
const fileName = 'poster.jpg';this should be a unique filename. Consider using UUID, adding a randomly generated hash, or timestamp (+new Date()) to create a random file name. - If you don’t change the filename, are you worried about synchronous requests picking up on the same file by other users?
- You should probably store the files in a sub-folder, not the root folder.
- Once it’s uploaded into Strapi’s media folder, you should probably delete the image (poster.jpg).
- Your image size is relatively small, any reason why it’s not bigger (> 2,000 px)? You can create a large image now and create smaller versions using Strapi’s Media Library breakpoint settings.
a) This will help later if you need to create larger versions of the images you have already generated in the past.
I hope this helps!