我目前在 heroku 上有一个站点,并且正在使用 postgreSQL。当我将 pdf 文件上传到数据库时,我将它们编码为 base64 并将它们保存为文本。我可以单击链接解码文件并毫无问题地下载;但是,我遇到了一个页面,其中有一个 iframe,其中包含 pdf 文件。如何将新解码的文件提供给 iframe?即使没有 iframe,我如何才能解码文件并将其作为页面?
我在想我可以创建一个 pdf 控制器,解码文件并显示打开文件,但我什至无法让它工作。
谢谢您的帮助!
编辑:这是我到目前为止所拥有的。
def create
@course = Course.find(params[:note][:id])
params[:note][:content].tempfile = Base64.encode64(open(params[:note][:content].tempfile).to_a.join)
params[:note][:filename] = params[:note][:content].original_filename
params[:note][:contenttype] = params[:note][:content].content_type
@note = @course.notes.build(:content => params[:note][:content].tempfile, :filename => params[:note][:filename],
:contenttype => params[:note][:contenttype])
if @note.save
flash[:success] = "File Uploaded!"
redirect_to root_path
end
这将文件保存为 base64 没有问题。不过,我不太确定下一部分。
def show
@note = Note.find(params[:id])
@notecon = @note.content
decoded_data=Base64.decode64(@notecon)
file_name = "test"
@temp_file = Tempfile.new("filename-#{Time.now}")
File.open(@temp_file, 'wb') {|f| f.write(decoded_data)}
end
现在,在视图中,我不知道将什么作为文件路径。
<iframe src="http://docs.google.com/gview?url=http://localhost:3000/app/views/notes/test&embedded=true"
style="width:718px; height:700px;" frameborder="0"></iframe>
我什至不知道如何发布保存在我的驱动器上的 pdf 文件。再次感谢!