carrierwaveuploader / carrierwave Goto Github PK
View Code? Open in Web Editor NEWClassier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
Home Page: https://github.com/carrierwaveuploader/carrierwave
Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
Home Page: https://github.com/carrierwaveuploader/carrierwave
I don't think the s3_headers thing is working correctly. Either that, or I'm doing something wrong ;)
In an initializer, I have:
CarrierWave.configure do |config|
config.s3_access_key_id = CONFIG['s3_access_id']
config.s3_secret_access_key = CONFIG['s3_secret_key']
config.s3_bucket = CONFIG['s3_bucket_name']
config.s3_access = :public_read
config.s3_headers = {'Cache-Control' => 'max-age=315576000', 'Expires' => 99.years.from_now.httpdate}
end
When I boot the app, I get:
undefined method `s3_headers=' for CarrierWave::Uploader::Base:Class
Because the model is not saved in before hooks one can't use model.id or other properties which are filled after model is saved. So for example using Sequel one can't use the model.id in the Uploader#store_dir because method is called before the save and the model.id is unknown.
Is it as easy as using after save hooks or it gets more complicated?
I had a little trouble getting random filenames to work by defining the "filename" method. I ended up finding a workaround, but I thought it might be worth mentioning in any case:
I dug around in the gem, but I couldn't seem to figure out if/why the filename was being set twice in my app.
There needs to be a way how to show what's going on during the image processing or model saving. Now it's king of a black box.
Set logger according to the framework and log as info level could be a way to go.
...would be nice. =)
Hi,
I would like to use CarrierWave with Rails 3 but Bundler needs the gemspec file for the following line :
gem "carrierwave", :git => "git://github.com/jnicklas/carrierwave.git"
hey, I have a site using CW with GridFS, ruby driver 0.18.3. It worked fine with 0.4.4 but when I updated to 0.4.5 it blows up with this:
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
from /Library/Ruby/Gems/1.8/gems/mongo-0.18.3/lib/../lib/mongo/connection.rb:303:in connect_to_master' from /Library/Ruby/Gems/1.8/gems/mongo-0.18.3/lib/../lib/mongo/connection.rb:121:in
initialize'
from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/storage/grid_fs.rb:89:in new' from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/storage/grid_fs.rb:89:in
database'
from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/storage/grid_fs.rb:77:in retrieve!' from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/uploader/store.rb:73:in
retrieve_from_store!'
from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/uploader/callbacks.rb:13:in with_callbacks' from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/uploader/store.rb:72:in
retrieve_from_store!'
from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/mount.rb:287:in uploader' from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/mount.rb:168:in
front'
from /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/mount.rb:156:in `front'
from (irb):2
I see that an optional port variable can be passed in but looking at the code I don't see where the problem is. Anyone else had this issue?
UPDATE: I found the cause of the problem. In line 53 of http://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/uploader/configuration.rb, change config.grid_fs_host to config.grid_fs_port ; )
I'm using
after_initialize { |track| track.uuid = random_generator }
mount_uploader :file, FileUploader
in my model, and
def filename
"#{model.uuid}.xxx"
end
in FileUploader, the :audio column will always store '.mp3' even if the uuid is there.
http://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/storage/s3.rb#L134
shouldn't be s3_bucket?
Using carrierwave master for some rails 3 goodness... Tried to run the generator (which I understand might not be working yet) and it stated "Could not find "uploader.rb" in source paths.". No biggie. I figure I'll just copy the contents of uploader.rb manually to app/uploaders... but there is no uploader.rb in the repo...
Guidance?
Duh, I read some commit history and crop_resized has been removed. That's what was causing it. Sorry for the noise!
This caught be out by creating lots of dummy files, when new entries were created without a file attached. My solution was to patch the rails generator comments incase somebody actually needs that functionality...
http://github.com/samlown/carrierwave/commit/825b8815d822152069875b641bef48189aa30e02
sam
I was able to add a custom config var by adding the following to my initializer:
CarrierWave::Uploader::Base.add_config :grid_fs_port
But seeing as having a custom port to a Mongo server is probably a pretty common thing, it might make sense to add this into the default config vars.
The s3_headers option was added without a default, breaking any app using carrier_wave and S3 it seems. It probably should default to {} to avoid issues.
The problem is on line 99 in lib/storage/s3.rb:
["http://", @uploader.s3_bucket, @path].compact.join('/')
Joining the bucket name and "http://" with a '/' results in something like "http:///my-bucket.example.com". Every browser I've tried seems to accept this, but it should just be two slashes.
One of the biggest selling points of Paperclip (and the reason I wont switch to carrierwave) is because of the direct integration with ImageMagick. If CW was able to integrate, then really there would be no reason to use any other file upload plugin/gem. How hard would it be to pull off?
Hi. Took me a while to discover that after adding carrierwave my CouchDB models stopped working when some of the class methods couldn't be found. Perhaps there are other modules with the same issue.
I've no doubt there is probably some strangeness in CouchRest that doesn't help, but does carrierwave really need to depend on such hacks when an include would suffice? The top of carrierwave/core_ext/inheritable_attributes.rb says it all:
# Retain for backward compatibility. Methods are now included in Class.
Otherwise, the plugin looks cool, I like the approach, and if possible I'd like to add CouchRest::ExtendedDocument support at some point.
Cheers, sam
When trying to use carrierwave on heroku, I received this error:
Errno::EROFS: Read-only file system - /disk1/home/slugs/76400_2681065_f91e/mnt/public/uploads - Heroku has a read-only filesystem. See http://docs.heroku.com/constraints#read-only-filesystem
I was able to work around the issue by reading about it here:
http://codingfrontier.com/carrierwave-on-heroku
The bare minimum needed to work around the issue is to add the following to your Uploader class:
def cache_dir
"#{RAILS_ROOT}/tmp/uploads"
end
Please feel free to close this issue. I just want to make sure it's easy to locate for other people that might have the same problem. It may also be worth mentioning in the docs.
My apologies for being so bothersome with all these issues ;) I'm finding carrierwave to be a real pleasure to work with, and my hope in documenting these small gotchas is that other people will be able to more easily use carrierwave in the future. Thank you!
HTML forms do not have a mechanism for removing uploaded files, there should be a built in mechanism so that we can have a check box which removes the file.
When using file storage, CarrierWave::SanitizedFile#content_type always returns nil, because @content_type is set to nil and @file is a string (path to a file), not an actual File instance.
When I add
gem.config 'carrierwave'
to my environment.rb I get the following error:
/Library/Ruby/Gems/1.8/gems/carrierwave-0.4.3/lib/carrierwave.rb:10: warning: already initialized constant VERSION
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:426:in `load_missing_constant': Expected /Library/Ruby/Gems/1.8/gems/carrierwave-0.4.3/lib/carrierwave.rb to define Carrierwave (LoadError)
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing_not_from_s3_library'
from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
from /Users/theo/…/config/initializers/carrierwave.rb:1
(path to the app elided for my privacy)
It seems like Rails expects carrierwave.rb to define Carrierwave (lowercase w), but it defines CarrierWave (uppercase w). Adding
config.gem 'carrierwave', :lib => 'CarrierWave'
doesn't solve the problem.
I'm using Rails 2.3.5.
Hello,
I want to save all uploaded pictures to png format so I use the following code in my picture_uploader.rb
process :convert => :png
If I do that uploaded file is save as foo.jpg and is in jpg format. So I've overloded the filename methods
def filename
"#{model.id}.png" if original_filename
end
And with that the file is save as #####.png but is still in jpg format.
I don't think the problem is with ImageMagick or RMagick because this test work just fine
process :to_format => :png
def to_format(format)
manipulate! do |img|
img.format = format.to_s.upcase
img = img.sepiatone
img.write('foobar.png')
img
end
end
The picture is saved as foobar.png and its format is really png.
I've read a lot of your code but I can't figured out why this doesn't work but I've found a strange (to my eyes :-) piece of code in carrierwave/lib/carrierwave/processing/rmagick.rb
module ClassMethods
def convert(format)
process :resize_to_limit => format
end
Should it be something like that no ?
def convert(format)
process :convert => format
end
EU buckets can't be accessed using the bucket name in the path, they can only be accessed through virtual domains.
Works: http://eu-bucket-name.s3.amazonaws.com/keyname
Doesn't work: http://s3.amazonaws.com/eu-bucket-name/keyname
Carrierwave always uses the path url.
The problem is even worse as AWS-S3 doesn't support EU-buckets either. There are a patch that can be used at http://github.com/vladr/aws-s3/commit/a13504ba581496eab253583f38d26aa475949b53
rightaws-s3 do support EU Buckets.
To do in carrierwave:
Serializing to json, when using default to_json causes SystemStackError (stack level too deep). I believe that is because Uploader object holds reference to parent item.
I'm sure I've missed something, but no matter where I put the CarrierWave.configure section for providing the S3 connection details it complains that it cannot find the configure method for the Module:
.../config/initializers/carrierwave_s3.rb:1:NoMethodError: undefined method `configure' for CarrierWave:Module
I'd also like to put it in the environment initializers so that I can use different settings depending on the environment, but it can't find the configure method then either.
Is there something I'm missing?
Cheers, sam
I tried to configure s3_headers using the CarrierWave.configure block method in an initializer and got the following error message:
undefined method `s3_headers=' for CarrierWave::Uploader::Base:Class
Overriding the s3_headers method in my uploader works fine.
This is more of a feature request, but it would be cool if storing files to MongoDB's built-in filesystem was an option. The simplicity of storing all the assets of a site - files and data - in one place is one of MongoDB's best features.
It would be useful to add before, after, around callbacks to the cache! and store! methods
store! won't save a file from a provided uri. An example is below:
require 'open-uri'
...
uploader = ImageUploader.new
uploader.store! open("http://example.com/image.gif")
Hi,
from this commit http://github.com/jnicklas/carrierwave/commit/cc12d370c08d8e421769bb4ce284762441bf1145#L0L98
my s3 european buckets did't work.
I changed my uploader with this config:
config.s3_bucket = 'assets-web.s3.amazonaws.com' config.s3_cnamed = true
I can see perfectly my assets but I can't upload them.
ERROR - [07/Mar/2010 18:54:53] "RightAws::AwsError - NoSuchBucket: The specified bucket does not exist: /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/right_aws-1.10.0/lib/awsbase/right_awsbase.rb:359:in `request_info_impl' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/right_aws-1.10.0/lib/s3/right_s3_interface.rb:169:in `request_info' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/right_aws-1.10.0/lib/s3/right_s3_interface.rb:403:in `put' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/storage/right_s3.rb:111:in `store' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/storage/right_s3.rb:146:in `store!' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/uploader/store.rb:58:in `store!' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/uploader/callbacks.rb:13:in `with_callbacks' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/uploader/store.rb:57:in `store!' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/mount.rb:325:in `store!' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/carrierwave-0.4.5/lib/carrierwave/mount.rb:216:in `store_file!'
Any chance we can add config options for gridfs?
Find a better solution for file deletion
This thread explains my problem - http://groups.google.com/group/carrierwave/browse_thread/thread/48b884fe2eb7d827
I had a dig around and can't seem to find where the content type is being set. Is it in sanitized_file? and where are the tests for the content type. If you point me in the right direction I can maybe spare some time to look at it.
Hi, in the README you write:
It might be a good idea to show the user that a file has been uploaded, in the case of images, a small thumbnail would be a good indicator:
<% form_for @user do |f| %>
<p>
<label>My Avatar</label>
<%= image_tag(@user.avatar.url) if @user.avatar %>
<%= f.file_field :avatar %>
<%= f.hidden_field :avatar_cache %>
</p>
<% end %>
It should be:
<%= image_tag(@user.avatar.url) if @user.avatar.url %>
Jonas, great upload gem. I really like it - was super easy to get started with. Thank you.
I am getting one error related to using it with mongomapper, but I realize you just added this support.
The error is 'Type error: can't modify frozen object' when doing User.destroy_all or User.first.destroy, etc. The error is only on destroy and the user actually gets destroyed, but tests fail because of the ugly error.
Following is the stacktrace with the rspec test I'm running. I had the same issues when running in merb -i -e test|development
I do not get the same error if I delete by doing: User.delete(@u.id) or User.delete_all
Possibly, it's related to MongoMapper's destroy method in lib/document.rb lines 302-308?:
def destroy
return false if frozen?
criteria = FinderOptions.to_mongo_criteria(:_id => id)
collection.remove(criteria) unless new?
freeze
end
Can reproduce error by:
class Product < ActiveRecord::Base
mount_uploader :image, ProductImageUploader
end
Product.all.to_json
Fix:
In uploader/url.rb
def to_json(options)
{ 'url' => url }.to_json(options)
end
I'd submit a patch, but I don't know how. Thanks!
When writing to S3 you need config.s3_bucket to not have the full domain name i.e. just the bucket name.
When reading from S3 you need config.s3_bucket to have the full cname domain. This breaks writing (no such bucket).
My Rails application requires that a user be able to "detach" an image that has been uploaded. How is this achieved with CarrierWave? I would expect @post.image = nil; @post.save
to do this, but the @post.image
persists as an ImageUploader
instance with a file
attribute pointing to a file on S3.
Manifest.txt contains references to:
lib/carrierwave/uploader/default_path.rb
spec/uploader/default_path_spec.rb
.. which don't exist.
update: didn't see the "rake manifest" tool. I can't run it though, complains about a missing .hoerc file - needs to be added? Anyway added the files manually + sent pull request; you may just want to run the rake tool, though...
Hi,
first thanks for this beautiful gem !
One question, but If I have a model and this model has_many mount_uploaders ?
Generally I have 1/2/3 attachment for model, but in much cases my model can have X (non predicted) attachments.
How we can do that?
While moving from paperclip to carrierwave, I ran into a little gotcha with machinist.
With paperclip, you can simply use a sham file name in a blueprint. With carrierwave, it seems to require having an actual file.
For example:
You can feel free to close this issue, but I wanted something available for our friendly google searchers ;)
If you think it's appropriate, it might be worth mentioning in the docs somewhere.
CarrierWave.clean_cached_files! references CarrierWave.root, which is not the correct directory to be deleting files from if you modify your cache_dir inside of an Uploader (i.e. to circumvent Heroku's read only file system). Perhaps we could have a config setting that allows us to define multiple paths to check for tmp files when running CarrierWave.clean_cached_files!, with a default of CarrierWave.root.
And we might as well also create a default rake task while we're at it.
A minor thing, but I'm wondering why carrierwave us using "public/uploads" as the tmp dir. I've had to add the following to my .gitignore:
public/uploads/*/
...but is there a reason that you might not just use the pre-existing tmp/ directory? If not, perhaps this is worth mentioning in the readme?
The way things work currently, I don't think you can specify an empty store_dir for s3. If you do, you'll get an extra "/" in the url. For example:
http://s3.amazonaws.com/example//ddc2edb.mp3
Note the double "/" after "example".
I think this could be fixed in the storage/s3.rb#url method, but I'm not sure...
[edit]
FWIW - I'm able to work around this issue like so for now:
I'm trying to figure out how to make this work in all cases, though.
[edit]
On a related note, I noticed that there are two definitions of the url method:
I'm wondering if there's a reason they are different and/or might these two methods be shared somehow?
[edit]
In my limited testing, it seems that right_aws doesn't play well with trying to upload files when given an empty store_dir. I discuss a bit further in this issue:
http://github.com/jnicklas/carrierwave/issues/issue/8#issue/8/comment/123665
...but the takeaway is that aws/s3 works as expected if given an empty store_dir, but right_aws does not. I'm not sure if this is a problem with carrierwave or not, though.
[edit]
This comment:
http://github.com/jnicklas/carrierwave/issues/closed/#issue/8/comment/123710
...was correct. Using "nil" instead of a blank string works for right_aws, but it requires overriding the store_path method like so:
After config.gem 'carrierwave' in a Rails 2.3.5 app with DM 0.10.2 doing a DataMapper.auto_migrate! results in stack level too deep.
It appears that no matter what contentType of file that I upload when I inspect the db from mongo shell it is always text/plain
carrierwave throws an error in Rails 3 edge because write_attribute is now a private method.
It can be changed to:
alias_method :read_uploader, :[]
alias_method :write_uploader, :[]=
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.