Skip to content

Use uploader class for carrierwave#143

Open
Nitr wants to merge 2 commits into
kreativgebiet:masterfrom
BrandyMint:nitr/feature/carrierwave_uploader
Open

Use uploader class for carrierwave#143
Nitr wants to merge 2 commits into
kreativgebiet:masterfrom
BrandyMint:nitr/feature/carrierwave_uploader

Conversation

@Nitr

@Nitr Nitr commented Feb 28, 2014

Copy link
Copy Markdown
Contributor

No description provided.

@ricbermo

ricbermo commented Apr 9, 2014

Copy link
Copy Markdown

This is a very nice feature, but, what if the user doesn't define any version?.

@Nitr

Nitr commented Apr 10, 2014

Copy link
Copy Markdown
Contributor Author

https://github.com/bastiaanterhorst/rich/blob/master/lib/rich.rb#L11
image_styles has default version always.
Did you mean it?

@ricbermo

Copy link
Copy Markdown

Yes, sorry, my fault. didn't see that. may I ask you something, are you getting an error with fog when you use amazon s3 as storage?. I'm getting one weird error.

@Nitr

Nitr commented Apr 10, 2014

Copy link
Copy Markdown
Contributor Author

I don't use fog yet(with rich). Error from amazon or rich code? Show me messages! =)
And now I think, use rich in production is not good idea, because no specs. =(

@ricbermo

Copy link
Copy Markdown

Hi, i was about to update my comment, this is what is causing the "fog" problem; it's not fog actually,
https://github.com/BrandyMint/rich/blob/nitr/feature/carrierwave_uploader/lib/rich/backends/carrierwave.rb#L41

@ricbermo

Copy link
Copy Markdown

I could find the error I was trying to let you know before, if I don't include

version :rich_thumb do
    process :resize_to_fit => [100, 100]
end

in my custom uploader I get this error:
undefined method `version' for Rich::Backends::CarrierWave::DefaultCarrierwaveVersions:Module (NoMethodError)

This is also happening when I set a custom version in my uploader

@ricbermo

Copy link
Copy Markdown

I change your code to this

module DefaultCarrierwaveVersions
  Rich.image_styles.each do |name, size|
    unless Rich.uploader.constantize.versions.include? name
      Rich.uploader.constantize.send :version, name.to_s do
        process :resize_to_fit => size.gsub("#", "").split("x").map(&:to_i)
       end
    end
  end
end

and now the versions are working (the ones you set in rich initializer and removing the versions from my custom uploader)

@Nitr

Nitr commented Apr 10, 2014

Copy link
Copy Markdown
Contributor Author

And yet I think, making preview image(rich_thumb) with PaperClip or Carrierwave is not good. We need add to model RichFile column preview, which will not be depend of image_styles and any image uploaders.

@ricbermo

Copy link
Copy Markdown

My friend, there's something new that you should change in your commit in order to make it work with fog and your custom uploader.

def uri_cache
  uri_cache_attribute = read_attribute(:uri_cache)
  if uri_cache_attribute.blank?
    uris = {}

    rich_file.versions.each do |version|
      uris[version[0]] = rich_file.url(version[0].to_sym)
    end

    #manualy add the original size
    uris["original"] = rich_file.url

    uri_cache_attribute = uris.to_json
    rich_file.model.update_attribute(:uri_cache, uri_cache_attribute)
  end
  uri_cache_attribute
end

Please, add a comment to your PR to let know that this pull requests allows amazon S3 as storage too.

@ricbermo

Copy link
Copy Markdown

Another thing, you cannot use the same uploader for images and files :/

@leofrozenyogurt

Copy link
Copy Markdown

Are we going to be able to use S3 then with this merge?

@ricbermo

Copy link
Copy Markdown

yes. the uploader can be configured in order to use S3.

@leofrozenyogurt

Copy link
Copy Markdown

any direction to this?
i currently have config.backend = :carrierwave
and my carrierwave initializer set up for fog/s3 storage

@ricbermo

Copy link
Copy Markdown

to be honest I don't remember but I'd say that it's exactly how you did it. Set up your backend to carrierwave, set the name of your carrierwave uploader and config your uploader with fog to use S3. Check the code to be sure.

@leofrozenyogurt

Copy link
Copy Markdown

Ahhh how do you set up the name of the carrierwave uploader in rich.

I have an uploader called ImageUploader which uses fog for my other images but how can i get fog to use this as well?

@ricbermo

Copy link
Copy Markdown

@leofrozenyogurt

Copy link
Copy Markdown

tried this
config.uploader :rich_file_file_name, ImageUploader
and it still didnt work

@ricbermo

Copy link
Copy Markdown

my friend, I think the correct config is
config.uploader: "ImageUploader"

@leofrozenyogurt

Copy link
Copy Markdown

that didnt work either.

So i set fog as global store but i am now getting this error

NoMethodError - undefined method `merge' for false:FalseClass:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants