2011-09-01 13 views
5

Risolto, vedere la modifica in fondo.Salva PDF generato dal sistema su S3


Nei miei 3.1 applicazione Rails sto generando un pdf in questo modo:

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 

Poi sto cercando di negozio che ha generato il PDF S3 caricando con il Paperclip:

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 

Ma mi sta dando "\x9C" from ASCII-8BIT to UTF-8

Come posso utilizzare Paperclip per caricare questo generato pdf a S3? Sto usando Heroku quindi non posso salvare un file temporaneo sul server e poi caricarlo.

//// risolto

Oh, il mio male, si può store files for the duration of the session at root.

Così funziona:

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

lo farò - avete bisogno di più rappresentante di quello che ho persino di rispondere, per non parlare di accettare, il proprio Q entro 8 ore di scriverlo. – snowangel

risposta

3

Oh, il mio male, si può store files for the duration of the session at root.

Così funziona:

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 
Problemi correlati