我在本地工作,将模板文件存储在#{Rails.root}/tmp
, using system "cd tmp/template; zip -r ../#{@filename} *"
压缩文件,将 .docx(zip 存档)发送到 S3,然后发送到浏览器。问题是 Heroku 找不到这些文件。在创建 xml 文件之前,我从另一个位置复制模板目录(system "cp -R support/ser_template tmp/"
)。我理解 Heroku 的只读文件系统但我不能拥有#{Process.pid}
我的文件名乱七八糟(Word 要求将 xml 文件命名为 document.xml)。
我是否可以将模板文件存储在 Amazon 上并仍然使用 Heroku 的系统 zip 实用程序?RubyZip 无法创建正确的 docx 档案.
编辑:这是代码:
require 'aws/s3'
class WordDocument
include ConnectS3
def initialize(content)
connect_s3
@pid = Process.pid
@filename = "SER_" + Time.now.strftime("%Y%m%d-%H%M%S") + '.docx'
system "cp -R #{Rails.root}/support/ser_template #{temp_path}"
xml = File.open(xml_path, 'w')
xml.puts content
xml.close
system "cd #{temp_path}; zip -r #{@filename} *"
docx = File.open(temp_path + "/" + @filename, 'r')
AWS::S3::S3Object.store(s3_path, docx, @s3_credentials["bucket"], :use_virtual_directories => true)
AWS::S3::S3Object.grant_torrent_access_to s3_path, @s3_credentials["bucket"]
end
def temp_path
"#{Rails.root}/tmp/#{@pid}_ser"
end
def xml_path
temp_path + "/word/document.xml"
end
def path
"https://s3.amazonaws.com/" + @s3_credentials["bucket"] + s3_path
end
def s3_path
'/section_editor_reports/' + @filename
end
end
你不能只在其中创建一个目录吗#{Rails.root}/tmp
打电话,说,#{Process.pid}_docx/something_nice/
?将您需要的内容复制(或符号链接)到:
#{Rails.root}/tmp/#{Process.pid}_docx/something_nice/
Then
system "cd #{Rails.root}/tmp/#{Process.pid}_docx/; zip -r x.zip something_nice"
然后你有:
#{Rails.root}/tmp/#{Process.pid}_docx/x.zip
有一个漂亮的内部结构,不包括你的 PID。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)