如何将heroku上的回形针上传目录更改为/ tmp? [英] How can I change the upload directory for paperclip on heroku to /tmp?

查看:130
本文介绍了如何将heroku上的回形针上传目录更改为/ tmp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要上传文件,然后使用回形针进行解析?



目前它上载到/ system文件夹中,这在heroku中是不允许的。



我不需要将上传文件保留下来,然后将其解析并存储。

我希望能够保存到/ tmp然后解析,然后让它在稍后被吹走。



想法如何做到这一点(如果我应该做这个)?

解决方案

Heroku的文档说使用

好吧,它在文档中说:

>

有两个目录是
可写的:./tmp和./log(在
应用程序根目录下)。如果您希望在
请求期间暂时放弃
a文件,您可以写入
文件名,如
#{RAILS_ROOT} / tmp / myfile _#{Process.pid }。
不能保证这个文件
会在随后的请求
中(尽管可能是),所以这个
不能用于任何类型的永久
存储


然后,如果您点击下面的Adam Wiggins链接,他说这可以通过Tempfile界面获得。 p>

使用Tempfile很容易,但如果heroku考虑读/写文件操作不同的进程,则文件可能不存在。

#tempfile_example.rb 
require'tempfile'

#默认为Dir :: tempdir
x = Tempfile.new('imagefile.png' )

放置x.path

编辑:答案


答案实际上是设置:path =>...但你接近.... - Angela



I need to upload files and then parse them using paperclip?

Currently it is uploaded in the /system folder, which isn't allowed in heroku.

I don't need the uploads to be persistent...I parse it and then store them.

So I'd like to be able to save into /tmp and then parse, and then let it get blown away later.

Thoughts on how to do this (if I should do this)?

解决方案

Heroku's docs say to use Tempfile.

Well, it says in the doc:

There are two directories that are writeable: ./tmp and ./log (under your application root). If you wish to drop a file temporarily for the duration of the request, you can write to a filename like #{RAILS_ROOT}/tmp/myfile_#{Process.pid}. There is no guarantee that this file will be there on subsequent requests (although it might be), so this should not be used for any kind of permanent storage

Then, if you click on the Adam Wiggins link below that, he says this is available through the Tempfile interface.

Using Tempfile is easy, but your file may not exist if heroku considers read/write file operations different processes.

# tempfile_example.rb
require 'tempfile'

# defaults to Dir::tempdir
x = Tempfile.new('imagefile.png') 

puts x.path

Edit: The Answer

The answer is actually to set :path => " " ... but you were close.... – Angela

这篇关于如何将heroku上的回形针上传目录更改为/ tmp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆