简体   繁体   English

使用http基本身份验证通过回形针从URL保存图像

[英]Save image from URL by paperclip using http basic authentication

How can i save an image from an URL which is authenticated using http basic authentication, using paperclip? 如何使用回形针从使用http基本身份验证进行身份验证的URL中保存图像?

I imagine the solution something like this: 我想象解决方案是这样的:

require "open-uri"

class User < ActiveRecord::Base
  has_attached_file :picture

  def picture_from_url(url)
    self.picture = open(url)
  end
end

But i need to put the credentials. 但是我需要把凭据。 How can i solve this? 我该如何解决?

Thanks 谢谢

I solved my problem with the link http://blog.andreamostosi.name/2013/04/open-uri-and-basic-authentication/ 我通过链接http://blog.andreamostosi.name/2013/04/open-uri-and-basic-authentication/解决了我的问题

require "open-uri"

class User < ActiveRecord::Base
  has_attached_file :picture

  def picture_from_url(url)
    self.picture = open(url, http_basic_authentication: ['user', 'password'])
  end
end

And worked. 和工作。

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

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