GithubHelp home page GithubHelp logo

Comments (4)

janko avatar janko commented on May 23, 2024

When you do any kind of direct uploads (custom endpoint, S3, tus), Shrine won't extract the metadata automatically, and will instead just use metadata that was set on the client side. This is because, in order to extract metadata, Shrine needs to retrieve the file contents (though determine_mime_type and store_dimensions plugins usually need just first few kilobytes). And that can potentially be expensive if the file is uploaded to remote storage like S3.

You can enable metadata extraction on attachment assignment by loading the restore_cached_data plugin. This is useful if you want to validate the extracted metadata, but it means metadata extraction will happen in the foreground.

Shrine.plugin :restore_cached_data

Alternatively you can use the refresh_metadata plugin (which restore_cached_data uses internally) to trigger the extraction yourself. Then you could e.g. call it in a background job if you're using it, by putting it in the process step when cached file is uploaded to permanent storage:

Shrine.plugin :refresh_metadata
process(:store) do |io, context|
  io.tap(&:refresh_metadata!) # return original cached file with extracted metadata
end

from shrine-tus.

codezomb avatar codezomb commented on May 23, 2024

from shrine-tus.

codezomb avatar codezomb commented on May 23, 2024

Worked like a charm, thanks!

from shrine-tus.

janko avatar janko commented on May 23, 2024

Yes, it's also the case with option C, as Shrine doesn't differentiate between storages, as it avoids storage-specific logic in order for the behaviour to stay the same when switching between different storages.

I will add the note about extracting metadata to the README.

from shrine-tus.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.