是的,您可以在 Heroku 中将其下载到文件系统中。
我怀疑空间很大,但是您应该可以使用临时文件。大多数系统先将上传内容存储到临时文件系统中,然后再将其推送到其他地方。
我已经在这样做了,因为 Roo 是能够从流中打开 Excel 文件的补丁,但没有其他类型(csv、ods 等)。
def create_temp_file
filename = some_model.some_attachment.blob.filename
@tmp = Tempfile.new([filename.base, filename.extension_with_delimiter], binmode: true)
@tmp.write(ome_model.some_attachment.download)
@tmp.rewind
@tmp
end
# this is how you use it, note the rescue part
def access_the_file
spreadsheet = Roo::Spreadsheet.open(create_temp_file)
# access the spreadsheet as usual
rescue
@tmp&.unlink
end
这保留了文件前缀和扩展名(对于让 Roo 推断文件是什么很重要)并确保文件在完成后被删除。