Shrine

Shrine

  • Guides
  • Plugins
  • External
  • Discourse
  • GitHub
  • Wiki

›Metadata

Attachment

  • Active Record
  • Column
  • Entity
  • Model
  • Sequel

Flow

  • Backgrounding
  • Presign Endpoint
  • Upload Endpoint

Processing

  • Derivation Endpoint
  • Derivatives

Source

  • Data URI
  • Rack File
  • Remote URL

Validation

  • Remove Invalid
  • Validation
  • Validation Helpers

Metadata

  • Add Metadata
  • Determine MIME Type
  • Infer Extension
  • Metadata Attributes
  • Refresh Metadata
  • Restore Cached Data
  • Signature
  • Store Dimensions
  • Type Predicates

Downloading

  • Download Endpoint
  • Rack Response
  • Tempfile

Form

  • Cached Attachment Data
  • Form Assign
  • Remove Attachment

Settings

  • Default Storage
  • Default URL
  • Dynamic Storage
  • Multi Cache
  • Pretty Location
  • Upload Options
  • URL Options

Other

  • Atomic Helpers
  • Included
  • Instrumentation
  • Keep Files
  • Mirroring
Edit

Restore Cached Data

The restore_cached_data plugin re-extracts metadata when assigning already cached files, i.e. when the attachment has been retained on validation errors or assigned from a direct upload. In both cases you may want to re-extract metadata on the server side, mainly to prevent tempering, but also in case of direct uploads to obtain metadata that couldn't be extracted on the client side.

plugin :restore_cached_data
photo.image = { "id" => "path/to/image.jpg", "storage" => "cache", "metadata" => {} }
photo.image.metadata #=> { "size" => 4823763, "mime_type" => "image/jpeg", ... } 

It uses the refresh_metadata plugin to re-extract metadata.

← Refresh MetadataSignature →
Shrine
Docs
GuidesPluginsExternalContributing
Community
DiscourseStack Overflow
More
BlogGitHubStar
Follow @shrine_rb
Copyright © 2022 Janko Marohnić