2014-10-15 7 views
0

http_basic_authentication에서 보호되는 파일을 CarrierWave로 업로드하려고합니다. 다음은 테스트 코드입니다 :http_basic_authentication 보호 파일 CarrierWave를 사용하여 업로드하는 방법

hs = House.new 
hs.remote_house_url = "http://username:[email protected]:3000/houses/export.csv" 
hs.save! 

내가 파일을 기대하고있어 업로드 할,하지만 난 다음 얻을 : 나는 http_basic_authentication 자격 증명을주는 문제 알고

(13.2ms) BEGIN 
    (0.8ms) ROLLBACK 
ActiveRecord::RecordInvalid: The validation failed : House could not download file: userinfo not supported. [RFC3986] 
from /Users/htaidirt/.rvm/gems/ruby-2.1.1/gems/activerecord-4.0.0/lib/active_record/validations.rb:57:in `save!' 

을 (사용자 이름 & 비밀번호) 메시지 http_basic_authentication 덕분입니다. 그러나 그것을하는 올바른 방법은 무엇입니까? 감사.

답변

1

방금 ​​비슷한 문제가 발생했습니다. Carrierwave 기본적으로이 기능을 지원하지 않는 것

: OpenURI 대신은 (http://blog.andreamostosi.name/2013/04/open-uri-and-basic-authentication/ 내가 여기 있음)

open("http://www.your-website.net", 
    http_basic_authentication: ["user", "password"]) 

같이해야합니다, 당신은 URL의 일부로 기본 인증 자격 증명을 제공 할 수 없습니다. 지금은 원숭이가 CarrierWave :: Uploader :: Download :: RemoteFile 클래스를 패치하여 필수 기본 인증을 추가했습니다. 나는 이것의 더 좋은 버전을 풀 요청으로 제출할 것이므로 잘하면 보석에 추가 할 수 있지만 내용은 config/initializers/overrides.rb를 작성했습니다 :