Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fog_attributes cannot be set on a per-version basis #937

Closed
crazymykl opened this issue Dec 20, 2012 · 6 comments
Closed

fog_attributes cannot be set on a per-version basis #937

crazymykl opened this issue Dec 20, 2012 · 6 comments

Comments

@crazymykl
Copy link

I have an uploader which behind-the-scenes gives the uploaded files UUID filenames so they can be uniquely stored in S3. The content-disposition http header is used to allow users to retrieve the files by their original names. I am adding functionality which converts the file format for one version, and would like for that version to have different fog_attributes.

@elskwid
Copy link

elskwid commented Dec 25, 2012

@crazymykl, have you tied setting the attributes right on the uploader?

Most of what CarrierWave does is move around instances of Uploader. In the fog storage code I see the fog_attributes being set on the uploader. It's a little confusing but CarrierWave::Uploader::Configuration makes the settings like fog_attributes and fog_credentials available on the instance.

Anyway, without seeing where you're trying to make this change I can't help with it specifically - but you should be able to modify fog_attributes and have the new settings used when the file is stored

@crazymykl
Copy link
Author

Here is a gist of my uploader. Hopefully it makes clear my intent, which is for all versions but one to have the attributes set one way, and that one another way. https://gist.github.com/4381362

@bensie
Copy link
Member

bensie commented Jan 6, 2013

Fog attributes cannot be set per uploader. If you figured out a way to override it per uploader, it wouldn't be thread safe.

@bensie bensie closed this as completed Jan 6, 2013
@thebucknerlife
Copy link

@bensie is this still the case? As I've found an SO answer that outlines how - http://stackoverflow.com/a/19851520/2200834

Still not thread-safe to define a fog_attributes per uploaded? I want to use two different 'Cache-Control' settings.

@tory
Copy link

tory commented Nov 25, 2014

Since the fog_attributes method is called for each version of an Uploader, I managed to set an attribute on a per-version basis by checking the version name first, like so:

  def fog_attributes
    if version_name.to_s == "download" 
      {"Content-Disposition" => "attachment;filename=#{file_name}"}
    else
      super
    end
  end

@thebucknerlife you should be able to do the same, with 'Cache-Control'.

@thebucknerlife
Copy link

Thanks @tory !

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

No branches or pull requests

5 participants