3

我需要将一堆文件上传到 S3。我在使用carrierwave + fog上传文件的rails项目中......如果我执行以下操作,控制台一切正常:

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

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

但它只是不起作用,我不明白为什么......它给出了这个错误:

rake aborted!
Broken pipe (Errno::EPIPE)

任何人都知道可能会发生什么?这让我发疯......这是 --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'

谢谢!!

4

1 回答 1

0

几天前我遇到了这个问题,解决方案是我没有正确指定我的存储桶-因此可能值得一看以确保您的存储桶名称正确并且权限设置正确。当没有指定存储桶时,这似乎是一个可笑的普遍错误!

于 2013-02-12T16:08:04.663 回答