简体   繁体   中英

S3 upload files with rake script, carrierwave and fog not working

I need to upload a bunch of files to S3. I'm in a rails project using carrierwave+fog to upload the files... Everything works fine from the console, if I do the following:

image = ImageUploader.new
image.store!(File.open("image.jpg"))

This was to test, now I have to upload a bunch of files so I create a rake script inside the lib/tasks folder named upload.rake... Inside this upload.rake I do the following:

task :upload => :environment do

    path = "app/assets/images"

    Dir.foreach(path) do |file|
        if file != "." && file !=".."
            uploader = ImageUploader.new
            uploader.store!(File.open(File.join(path,file)))    
            puts file
        end
    end 
end

But it just doesn't work, I can't understand why... It gives this error:

rake aborted!
Broken pipe (Errno::EPIPE)

Anybody has an idea of what may be happening?? It's driving me crazy... this is the last part of the --trace

.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/openssl/buffering.rb:292:in `syswrite_nonblock'
.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/openssl/buffering.rb:292:in `write_nonblock'
.rvm/gems/ruby-1.9.2-p320/gems/excon-0.16.7/lib/excon/socket.rb:139:in `write'
.rvm/gems/ruby-1.9.2-p320/gems/excon-0.16.7/lib/excon/ssl_socket.rb:84:in `write'
.rvm/gems/ruby-1.9.2-p320/gems/excon-0.16.7/lib/excon/connection.rb:269:in `request_kernel'
.rvm/gems/ruby-1.9.2-p320/gems/excon-0.16.7/lib/excon/connection.rb:103:in `request'
.rvm/gems/ruby-1.9.2-p320/gems/fog-1.6.0/lib/fog/core/connection.rb:20:in `request'
.rvm/gems/ruby-1.9.2-p320/gems/fog-1.6.0/lib/fog/aws/storage.rb:392:in `request'
.rvm/gems/ruby-1.9.2-p320/gems/fog-1.6.0/lib/fog/aws/requests/storage/put_object.rb:43:in `put_object'
.rvm/gems/ruby-1.9.2-p320/gems/fog-1.6.0/lib/fog/aws/models/storage/file.rb:133:in `save'

Thanks!!

I was running into this a few days ago and the solution was that I wasn't specifying my bucket correctly - so It may be worth having a look to make sure that your bucket name is correct and that the permissions are set correctly on it. It seems to be a bit of a ridiculously general error when there is no bucket specified!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM