如何在载波中将文件存储在公用文件夹之外? [英] How to store files out side the public folder in carrierwave?

查看:60
本文介绍了如何在载波中将文件存储在公用文件夹之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Carrierwave会在上载器中使用 store_dir 生成的URL,并在rails应用程序的公用文件夹中添加路径并存储文件。

Carrierwave by default takes in the url generated by store_dir in the uploader and prepends the path to the public folder of the rails application and stores the files.

例如,如果

def store_dir
  "uploads/#{model.id}"
end

然后将文件存储在 public / uploads /:attachment_id

如果有人试图将存储的文件移出公共文件夹,它仍然保存在公共文件夹中。有没有人知道如何将文件存储在公用文件夹之外??

If one tries to move the stored files out of the public folder still it saves in the public folder. Does anyone have an idea of how to store the files outside the public folder??

推荐答案

最干净的方法是通过设置CarrierWave根选项

the cleanest way to do this, is by setting the CarrierWave root option

CarrierWave.configure do |config|
  config.root = Rails.root
end

然后 store_dir 将在此根目录内使用。

then store_dir will be used inside this root.

这篇关于如何在载波中将文件存储在公用文件夹之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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