有 Rails “image_tag”浏览 /public 文件夹外的图像?
我正在尝试将 Paperclip 与 Heroku 一起使用。是的,根据 Heroku 的应用程序限制。我只能将上传的文件存储到 /tmp 或 /.log 文件夹中,该文件夹完全位于 /public 文件夹之外。
如果我们不讨论 Amazon S3,我如何使用 image_tag 标签访问 /tmp 目录中的图像。
这是我的照片模型,使用回形针
class ObbProductphoto < ActiveRecord::Base
belongs_to :product
has_attached_file :photo, :styles => {:high => '1024x768', :medium => '640x480', :thumb => '100x100'},
:path => "tmp/:id.:extension",
:url => "tmp/:id.:extension"
end
这是我在浏览器中得到的:
<img src="/images/tmp/24.JPG?1294433924" alt="24" />
它仍然使用 /images 文件夹,
我试图破解任何 /.. 或 .. /,无法得到解决方案。
谢谢你们, 苏帕特
I am trying to use Paperclip with Heroku. And yes, according to Heroku's Application Constraints. I'll be able to store the uploaded files into /tmp or /.log folder only, which is totally located outside the /public folder.
If we are not going to talk about Amazon S3, how can I access the image in the /tmp directory with image_tag tag.
This is my model of the photo, that using Paperclip
class ObbProductphoto < ActiveRecord::Base
belongs_to :product
has_attached_file :photo, :styles => {:high => '1024x768', :medium => '640x480', :thumb => '100x100'},
:path => "tmp/:id.:extension",
:url => "tmp/:id.:extension"
end
And this is what I got in the browser:
<img src="/images/tmp/24.JPG?1294433924" alt="24" />
It still using the /images folder,
I tried to hack any /.. or ../, couldn't get the solution.
Thank you guys,
Suebphatt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您可以将文件放在比 /tmp 更永久的位置,则可以使用 :url 和 :path 参数以及一些配置工作。
从我最近编写的代码中提取的一个示例(它经过了足够的修改,如果逐字复制它可能无法工作):
请注意,这都是 Rails 3 语法。要在 Rails 2.x 中使用它,需要进行一些更改,但希望您能了解,嗯,图片。
Assuming you can put the files somewhere more permanent than /tmp, storing and accessing uploaded files outside the
public
directory is possible using the :url and :path parameters, along with a bit of configuration work.An example extracted from code I wrote recently (it's modified enough that it might not work if you copy it verbatim):
Note this is all Rails 3 syntax. A handful of changes would be needed to use it in Rails 2.x, but hopefully you get the, um, picture.
据我所知,你不能 -
/tmp
没有配置为可以提供项目的东西(它用于临时存储)。您可以在浏览器中访问
/tmp
URL 上的图像吗?它们有效吗?As far as I'm aware, you can't -
/tmp
isn't configured as something that you can serve items out of (it's intended for temporary storage).Can you access images at the
/tmp
URLs in your browser? Do they work?