繁体   English   中英

使用Rails和回形针为/ public文件夹中的文件设置限制

[英]Set restrictions for files in /public folder with rails and paperclip

我正在使用回形针进行图像存储,但我遇到了问题。 上载文件时,回形针会生成两个文件,一个带有水印的已处理图像和原始文件,在这种情况下,这些图像文件位于公用文件夹中,现在的问题是,如果用户输入该URL,我可以限制该URL吗?喜欢:

localhost:3000/files/photos/image_processeds/57308cd52cb1be0846e4be9f/original/image.png

如果用户输入链接,则将被禁止。

这是我的回形针配置

has_mongoid_attached_file :image_original,
                        :url => "/files/:class/:attachment/:id/:style/:basename.:extension",
                        :path => ":rails_root/public/files/:class/:attachment/:id/:style/:basename.:extension"

has_mongoid_attached_file :image_processed,
                        processors: [:watermark],
                        styles: {
                            thumb: ['150x150', :jpg],
                            small: ['350x300', :jpg],
                            medium: ['550x500', :jpg],
                            original: {geometry: '60%',watermark_path: "#{Rails.root}/public/images/logo.gif", position: "Center"}
                        },
                        :url => "/files/:class/:attachment/:id/:style/:basename.:extension",
                        :path => ":rails_root/public/files/:class/:attachment/:id/:style/:basename.:extension"

有办法做到这一点,或者为此找到更好的方法吗?

我猜应该对original/image.png加水印。 我的意思是没有水印的版本在处理后不应该存在。 你检查了吗?

解决了,一种可靠的解决方案是将原始图像的副本保存到数据库中,并仅在他们购买照片时才授予对它的访问权限,否则,他们只能看到带有水印的副本:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM