开发者

How to upload remote_url Images using paperclip plugin in Ruby on Rails

I am new ROR Developer. i want to upload more than 500000 remote url images using paperclip. i got an error

 Error = Too many links - /var/www/railsapp/sample_app/public/system/photos/5815
 Error = Too many links - /var/www/railsapp/sample_app/public/system/photos/48347
 .
 .
 .
 .
 .

 Time Out   :  Error = execution expired

 Error = undefined method `request_uri' for #<URI::Generic开发者_运维知识库:0x7f565dc6f218 URL:>

can you anybody clarify it? i struggle this position.

Here my rake task for uploading remote url images:

   Book.find_in_batches(:conditions=>["image_url is not null and book_id is not null and active=true"],:batch_size=>10000) do |books|
  books.each do |book|
    begin
      book=Book.find_by_id(book.book_id)
      url = URI.parse(book.image_url)
      Net::HTTP.start(url.host, url.port) do |http|
        if http.head(url.request_uri).code == "200"
          Book.update_attribute(:photo,open(url))
        end
      end
    rescue Timeout::Error => e
     app_logger.debug("Book Photo data load Time Out   :  Error = #{e}")
    rescue Exception => e
     app_logger.debug("Book Photo data load   :  Error = #{e}")
    end
  end

end


The problem is that you've reached the limit of the number of files you can put in a directory, add this to an initialiser in your rails app:

# put in /config/initializers/paperclip.rb 

Paperclip::Attachment.default_options[:url] = 
"/system/:class/:attachment/:id_partition/:style/:basename.:extension" 
Paperclip::Attachment.default_options[:path] = 
":rails_root/public/system/:class/:attachment/:id_partition/:style/:basename.:extension" 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜