# CarrierWave: 1 uploader for multiple file types

**URL:** <https://www.ruby-forum.com/t/carrierwave-1-uploader-for-multiple-file-types/192757>\
**Category:** Rails\
**Created:** [August 5, 2010, 1:25am UTC](https://www.ruby-forum.com/t/carrierwave-1-uploader-for-multiple-file-types/192757 "2010-08-05T01:25:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [August 5, 2010, 1:25am UTC](https://www.ruby-forum.com/t/carrierwave-1-uploader-for-multiple-file-types/192757/1 "2010-08-05T01:25:15Z")

</div>

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](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

> **[GitHub - carrierwaveuploader/carrierwave: Classier solution for file uploads...](https://github.com/carrierwaveuploader/carrierwave)**
>
> Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks - GitHub - carrierwaveuploader/carrierwave: Classier solution for file uploads for Rails, Sinatra and other Ruby ...

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
