Extracting image dimensions in the background

43 views
Skip to first unread message

jan....@gmail.com

unread,
Dec 25, 2018, 12:18:47 AM12/25/18
to Shrine
Hey Janko and team,

I have set up direct uploads to S3 with Shrine. This works great. Among others, I have the following plugins enabled:

Shrine.plugin :backgrounding
Shrine.plugin :store_dimensions 
Shrine.plugin :restore_cached_data

Correct me if I'm wrong but image dimensions extraction appears to be done synchronously. If I let the user bulk upload images via Uppy and then persist them all, this seems to be taking a long time.

What I'd like to do is perform image dimensions extraction asynchronously - I don't need the dimensions available for the cached file. If possible, I'd like to do that in the background when the file gets promoted to the store. Is there a way to do it? Maybe disabling store_dimensions plugin and defining a custom process(:store) block?

Many thanks!

P.S. also posted the question here.

Janko Marohnić

unread,
Dec 25, 2018, 3:08:01 AM12/25/18
to Shrine, jan....@gmail.com
Correct me if I'm wrong but image dimensions extraction appears to be done synchronously. If I let the user bulk upload images via Uppy and then persist them all, this seems to be taking a long time.

This is exactly what the restore_cached_data plugin does – it extracts metadata from directly uploaded files on assignment.

If you want to extract metadata in the background, you can use the refresh_metadata plugin (which restore_cached_data plugin uses internally) to extract metadata explicitly.

  Shrine.plugin :refresh_metadata

You can then call UploadedFile#refresh_metadata! in the processing block for background promotion.

  process(:store) do |io, context|
    io.refresh_metadata!(context)

    # processing

    { original: io, **versions }
  end

Kind regards,
Janko
--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/e493e27b-fedb-4c12-a089-dcf025149e3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jan....@gmail.com

unread,
Dec 25, 2018, 8:16:55 AM12/25/18
to Shrine
Thank you, Janko, that worked wonderfully! I'll update my original Stack Overflow question.

Best,
Jan
Reply all
Reply to author
Forward
0 new messages