2011-09-01 29 views
5

Được giải quyết, xem chỉnh sửa ở dưới cùng.Lưu trữ PDF do hệ thống tạo trên S3


Trong 3.1 ray của tôi ứng dụng tôi đang tạo ra một pdf như thế này:

def show 
    @contributor = Contributor.find(params[:id]) 

    respond_to do |format| 
    format.pdf { 
    html = render_to_string(:action => "show.html.erb") 
    kit = PDFKit.new(html) 
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
    thepdf = send_data kit.to_pdf, :filename => "blah.pdf", :type => 'application/pdf' 
redirect_to :action => save_to_s3  
} 
end 

Sau đó, tôi đang cố gắng để lưu trữ mà tạo ra PDF trên S3 bằng cách tải lên với Kẹp giấy:

def save_to_s3 
    html = render_to_string(:action => "show.html.erb") 
     kit = PDFKit.new(html) 
     kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
     roy = Royarchive.new(:client_id => @contributor.client_id) 
     f = File.open("blah.pdf", 'w+') 
     f.write kit.to_pdf 
     roy.pdf = f 
     roy.save! 
end 

Nhưng điều đó mang lại cho tôi "\x9C" from ASCII-8BIT to UTF-8

Làm cách nào để sử dụng Paperclip để tải ảnh này lên pdf đến S3? Tôi đang sử dụng Heroku vì vậy tôi không thể lưu một tập tin tạm thời trên máy chủ sau đó tải nó lên.

//// giải quyết

Oh, xấu của tôi, bạn có thể store files for the duration of the session at root.

Vì vậy, công trình này:

def show 
    @contributors = Contributor.where(:client_id => current_user.client_id).paginate(:page => params[:page]) 
    @contributor = Contributor.where(:client_id => current_user.client_id).find(params[:id]) 


    respond_to do |format| 
    format.html 
    format.pdf { 
    html = render_to_string(:action => "show.html.erb") 
    kit = PDFKit.new(html) 
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
    send_data kit.to_pdf, :filename => "name.pdf", :type => 'application/pdf' 
    @thepdf = kit.to_file("#{Rails.root}/tmp/name.pdf") 

roy = Royarchive.new(:client_id => @contributor.client_id) 
roy.pdf = @thepdf 
roy.save!  
    } 

end 
end 
+0

tôi sẽ - bạn cần nhiều đại diện hơn là tôi phải thậm chí trả lời, hãy để một mình chấp nhận, Q của riêng bạn trong vòng 8 giờ viết nó. – snowangel

Trả lời

3

Oh, xấu của tôi, bạn có thể store files for the duration of the session at root.

Vì vậy, công trình này:

def save_to_s3 
    html = render_to_string(:action => "show.html.erb") 
    kit = PDFKit.new(html) 
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
    thepdf = kit.to_file("#{Rails.root}/tmp/name.pdf") 

    roy = Royarchive.new(:client_id => @contributor.client_id) 
    roy.pdf = thepdf 
    roy.save! 
    redirect_to :action => index 
end 
Các vấn đề liên quan