简体   繁体   English

S3上传文件与rake脚本,carrierwave和雾无法正常工作

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

I need to upload a bunch of files to S3. 我需要将一堆文件上传到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: 我正在使用carrierwave + fog上传文件的rails项目...如果我执行以下操作,一切都可以从控制台正常工作:

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: 这是测试,现在我必须上传一堆文件,所以我在名为upload.rake的lib / tasks文件夹中创建了一个rake脚本...在这个upload.rake中我执行以下操作:

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 这让我发疯了......这是--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! 没有指定存储桶时,这似乎有点荒谬的一般错误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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