Shrine: Adding metadata to S3 storage

Created on 20 Nov 2017  路  2Comments  路  Source: shrinerb/shrine

I would like to add Cache-Control metadata to the uploads to S3 storage.
So in my uploader I added the add_metadata plugin.
I get the metadata information added to my database-record but I cannot see it on Amazon S3.

Code:

plugin :add_metadata
  add_metadata :'cache-control' do |io, context|
    'max-age=864000' # 10 days (3600*24*10 sec)
  end

Result in database:
{"content":{"id":"post/56/picture/content-bb09356fa4fd725e3dc1c91a9d75c52d.png","storage":"store","metadata":{"filename":"mini_magick20171120-94328-q11rfi.png","size":303622,"mime_type":"image/png","cache-control":"max-age=864000","width":800,"height":533}}

Most helpful comment

What @hmistry said is correct, you should use the upload_options plugin for setting :cache_control:

plugin :upload_options, store: {cache_control: "max-age=864000"}

All 2 comments

The add_metadata plugin main function is to add other information to the model in the database. The plugin does not know about S3 and how to change it's settings.

To change the Cache-Control data for the file in S3, use the upload_options plugin. There are 2 ways of setting it, either by storage or per file, see here. The options are forwarded to the aws-sdk-s3 gem internally so here's a list of valid options.

What @hmistry said is correct, you should use the upload_options plugin for setting :cache_control:

plugin :upload_options, store: {cache_control: "max-age=864000"}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Grafikart picture Grafikart  路  4Comments

brunowego picture brunowego  路  3Comments

abevoelker picture abevoelker  路  5Comments

Sohair63 picture Sohair63  路  3Comments

musaffa picture musaffa  路  7Comments