#Way to skip Sharp processing for specific mimetypes on upload?

3 messages · Page 1 of 1 (latest)

sick shore
#

Hey! Running into a wall with animated GIF uploads on Payload 3 + uploadthing, wondering if there's an official way to handle this that I'm missing.

The problem: When a user uploads a GIF to my media collection, Payload forces sharp({ animated: true }) in generateFileData and imageResizer, which processes every frame for the original + every imageSize variant. For a 4.4 MB GIF with 36 frames @ 1457×837, this easily exceeds 1 minute on a modest VPS and hits the reverse proxy timeout. In my frontend I only use next/image with the original URL (I don't consume any resized variants), so the work is pure waste for GIFs.

What I've tried:

  • Trimmed imageSizes down to just thumbnail + og → helps but still times out (the forced animated re-encode of the original at generateFileData alone is expensive).
  • Checked resizeOptions, formatOptions, trimOptions, constructorOptions... none let me skip the pipeline per-mimetype.
  • Thinking about trying a hook that mutates req.file.mimetype to application/octet-stream in beforeOperation so canResizeImage returns false and Sharp is skipped entirely, then restores mimeType/width/height in beforeChange. But is hacky and the file ends up stored in storage bucket with Content-Type: application/octet-stream.

Questions:

  1. Is there an official way to say "for this mimetype, skip Sharp entirely" that I'm missing?
  2. Any cleaner workaround you'd recommend for the meantime?

Thanks a lot!

gray thornBOT
iron mango
#

Did you ever figure this out? Ages ago when I used Craft CMS there was an option to bypass all image size processing for GIFs, currently Payload will create huge sprite sheets of every frame of the GIF