Generating photo previews on an S3 bucket

Hi all,
I’ve got a small EC2 server where my Nextcloud displays some content both from local folders and from an S3 bucket.
When it comes to generating photo previews, is it possible to generate all the files only on a specific folder of the S3 bucket? Or to avoid generating files on the local storage anyway?