Rails 和 Paperclip,使用不同的图像,而不是上传的图像进行处理

发布于 2024-10-10 02:48:34 字数 208 浏览 0 评论 0原文

我想知道有没有一种方法可以为回形针处理的图像指定不同的图像?

因此,不是用户上传图像,而是使用图像 url,或者认为可以指向服务器上现有的不同图像?

干杯。

编辑: 需要明确的是,我正在寻找的是,当图像被上传、处理、移动到文件夹并附加到文件夹时。该基本图像不是通过表单上传的,而是从 URL 中获取并进行处理、移动等。

I was wondering there was a way to specify a different image for the one to be processed by paperclip?

So instead of the user uploading an image, an image url would be used instead or an exsiting different image on your server thought could just be pointed to?

Cheers.

Edit:
Just to be clear, what I'm looking for is, when an image is uploaded, processed, moved to a folder and attached to a folder. That base image is not uploaded via a form but instead is fetched from a URL and them processed, moved etc 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2024-10-17 02:48:34

这是使用 RemoteFile 而不是上传文件的方法...查看博客文章,了解如何创建 RemoteFile,它是 TempFile 的子类

#console
remote_file = RemoteFile.new("http://www.google.com/intl/en_ALL/images/logo.gif")
remote_file.original_filename #=> logo.gif
remote_file.content_type #= image/gif

#controller
def import
  #...snip
  @imported_user.images.create(:file => RemoteFile.new( url_to_image ))
  #...snip
end

http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename -在临时文件中/

Here's a method to use a RemoteFile instead of an uploaded file... Check out the blog post for how to create a RemoteFile, which is a subclass of TempFile

#console
remote_file = RemoteFile.new("http://www.google.com/intl/en_ALL/images/logo.gif")
remote_file.original_filename #=> logo.gif
remote_file.content_type #= image/gif

#controller
def import
  #...snip
  @imported_user.images.create(:file => RemoteFile.new( url_to_image ))
  #...snip
end

http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/

扎心 2024-10-17 02:48:34

我不确定您的要求是否要求用户提供此图像,但如果他们不提供此图像,有一种方法可以拥有默认图像。这是使用 default_url 和默认样式选项完成的,如下所示:

has_attached_image :my_image
                   :default_url => "/path/to/default_image.jpg",
                   :default_style => :thumb

I'm not sure if your requirement is for the user to provide this image or not, but there is a way to have a default image if they don't provide one. This is done using the default_url and default style options like so:

has_attached_image :my_image
                   :default_url => "/path/to/default_image.jpg",
                   :default_style => :thumb
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文