解决了,见编辑在底部。
在我的3.1的Rails应用我生成一个PDF格式是这样的:
高清节目
@contributor = Contributor.find(PARAMS [:ID])
respond_to代码做|格式|
format.pdf {
HTML = render_to_string(:动作=>中show.html.erb)
包= PDFKit.new(HTML)
kit.stylesheets<< #{Rails.root} /app/assets/stylesheets/unique/print.css
thepdf = SEND_DATA kit.to_pdf,:文件名=> blah.pdf:类型=> 应用程序/ PDF
redirect_to时:行动=> save_to_s3
}
结束
然后我想生成PDF在S3上用回形针上传店:
高清save_to_s3
HTML = render_to_string(:动作=>中show.html.erb)
包= PDFKit.new(HTML)
kit.stylesheets<< #{Rails.root} /app/assets/stylesheets/unique/print.css
罗伊= Royarchive.new(:CLIENT_ID => @ contributor.client_id)
F = File.open方法(blah.pdf,W +')
f.write kit.to_pdf
roy.pdf = F
roy.save!
结束
但是,这给我的\ x9C从ASCII-8BIT为UTF-8
我如何使用回形针上传此生成的PDF到S3?我使用Heroku的,所以我不能保存在服务器上的临时文件,然后上传。
////解决
呵呵,我的坏,你的可以的store文件会议在根的持续时间。
所以这个作品:
高清节目
@contributors = Contributor.where(:CLIENT_ID => current_user.client_id).paginate(:页=> PARAMS [:页面])
@contributor = Contributor.where(:CLIENT_ID => current_user.client_id).find(PARAMS [:ID])
respond_to代码做|格式|
的format.html
format.pdf {
HTML = render_to_string(:动作=>中show.html.erb)
包= PDFKit.new(HTML)
kit.stylesheets<< #{Rails.root} /app/assets/stylesheets/unique/print.css
SEND_DATA kit.to_pdf,:文件名=> name.pdf:类型=> 应用程序/ PDF
@thepdf = kit.to_file(#{Rails.root} /tmp/name.pdf)
罗伊= Royarchive.new(:CLIENT_ID => @ contributor.client_id)
roy.pdf = @thepdf
roy.save!
}
结束
结束
解决方案
呵呵,我的坏,你的可以的store文件会议在根的持续时间。
所以这个作品:
高清save_to_s3
HTML = render_to_string(:动作=>中show.html.erb)
包= PDFKit.new(HTML)
kit.stylesheets<< #{Rails.root} /app/assets/stylesheets/unique/print.css
thepdf = kit.to_file(#{Rails.root} /tmp/name.pdf)
罗伊= Royarchive.new(:CLIENT_ID => @ contributor.client_id)
roy.pdf = thepdf
roy.save!
redirect_to时:行动=>指数
结束
Solved, see edit at bottom.
In my 3.1 rails app I'm generating a pdf like this:
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
Then I'm trying to store that generated PDF on S3 by uploading with 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
But that's giving me "\x9C" from ASCII-8BIT to UTF-8
How can I use Paperclip to upload this generated pdf to S3? I'm using Heroku so I can't save a temp file on the server then upload it.
////solved
Oh, my bad, you can store files for the duration of the session at root.
So this works:
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
解决方案
Oh, my bad, you can store files for the duration of the session at root.
So this works:
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
上一篇:拷贝或复制亚马逊RDS MYSQL周报亚马逊、周报、RDS、MYSQL
下一篇:如何通过HTTP_X_FORWARDED_FOR从IIS ASPX页面页面、HTTP_X_FORWARDED_FOR、IIS、ASPX