Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Extracting metadata #2

Closed
janko opened this issue Aug 9, 2016 · 2 comments
Closed

Extracting metadata #2

janko opened this issue Aug 9, 2016 · 2 comments

Comments

@janko
Copy link

janko commented Aug 9, 2016

Hey there,

I noticed your project, thanks for contributing to the Shrine ecosystem! 😃

I just wanted to give one suggestion about the direction of implementing this feature. The way that it's currently written, it will only work for FileSystem storage, because that's the only one for which the io will be a File object. It could work for remote storages by downloading the file, but that would be very slow if we want to display it on the page.

My proposal is that, instead of having this defined on UploadedFile and extracted ad-hoc, to extract it as metadata before upload. For example, if user is processing versions, that they can extract dominant color of a single version (just like in the carrierwave-color readme):

class ImageUploader < Shrine
  plugin :add_metadata

  add_metadata :dominant_color do |io, context|
    if context[:version] == :small
      dominant_color(io.path)
    end
  end
end
photo.image[:small].metadata["dominant_color"]
# or
photo.image[:small].dominant_color

This plugin could perhaps automatically do that under-the-hood. This way fetching the dominant color would be instant for any kind of storage, because it you would be just reading the metadata value. What do you think about it?

@jnylen
Copy link
Owner

jnylen commented Aug 11, 2016

Hi Janko,
Working on this now.

@mhluska
Copy link

mhluska commented Feb 5, 2020

I'm not actually sure this is working as @janko intended? For me, the io object is still an UploadedFile and I get:

NoMethodError Exception: undefined method `path' for #<ImageUploader::UploadedFile:0x00007fadb7bccdb8>

Mind you, I am doing direct to S3 uploads. Does that flow ever download the full file? I figured the promote stage still does download the file and I could extract the dominant color there.

Opened a new issue here explaining it: #5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants