Skip to content

Uploaded file processing #432

Answered by jmikrut
chladog asked this question in Q&A
Feb 8, 2022 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

Hey @chladog — good question!

What I'd do is probably leave the existing jpg / png in place, but add some new fields for your webp URLs to your upload-enabled collection. This way you still have the originals and can use them if your users' browsers are not webp-compatible.

Here's how I'd do it:

  • Use an afterChange collection hook
  • In the hook, take the file from the req, and the req.payloadUploadSizes, and then convert both the main file and each of your resized versions to webp
  • Save the webp versions to disk or wherever
  • Grab their filenames and then add their filenames to the new fields in your document

This could be a great plugin actually. I bet other people would have use for this as…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@chladog
Comment options

@denolfe
Comment options

Answer selected by chladog
Comment options

You must be logged in to vote
2 replies
@quornik
Comment options

@jmikrut
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants