I am using the carrierwave to upload files to a rails project. Right
now it works fine for uploading images but want to check if the file is
an image before attempting to resize it to avoid errors. What I’m
having trouble with is grabbing the filename of the current file it’s
trying to upload.
Using:
Ruby 1.8.7
rails 2.3.5
carrierwave 0.4.5
I used this thread as a starting point but ran into a wall
http://groups.google.com/group/carrierwave/browse_thread/thread/6e211d98f1ff4bc0
Currently my app/uploaders/my_uploader.rb looks like this
class MyUploader
…
if
MIME::Types.type_for(CURRENT_FILE).first.raw_media_type.eql?(“image”)
version :medium do
…
end
…
end
In the place of CURRENT_FILE I’ve tried a lot of different
variable/method names from the github readme at
Each time I come up with either “no method” “uninitialized constant” or
some similar error. I also tried splitting it up into an image? method
but that method wasn’t recognized either:
class MyUploader
…
if image?
version :medium do
…
end
def image?
MIME::Types.type_for(CURRENT_FILE).first.raw_media_type.eql?(“image”)
end
end
Even if the image? method was recognized I still need to get the current
file.
I posted a reply to Nicklas on the google group page, if anyone else can
shed some light on this that would be awesome!
Many thanks in advance,
Chris