2012-08-23 1 views
2

다음은 로컬 파일 시스템에서 원격 Apache 서버로 파일을 업로드하는 프로그램입니다.ruby ​​Net을 사용하여 파일 업로드하기 : 409와 충돌하는 원격 아파치 서버에 HTTP API 충돌

프로그램이 409 충돌 오류로 종료됩니다. 내가 뭘 잘못하고 있다는 충고가 있니? 나는 httpd.conf에서 DAV를 켜고 필요한 모든 권한을 주었지만 여전히 운이 없었습니다. 필요한 경우 httpd.conf를 게시 할 수 있습니다.

코드입니다 :

BOUNDARY = "AaB03xZZZZZZ11322321111XSDW" 
uri = URI.parse("http://localhost/dropbox/") 
file = "/tmp/KEYS.txt" 
http = Net::HTTP.new(uri.host, uri.port) 
request = Net::HTTP::Put.new(uri.request_uri) 
request.body_stream=File.open(file) 
request["Content-Type"] = "multipart/form-data" 
request.add_field('Content-Length', File.size(file)) 
request.add_field('session', BOUNDARY) 
response=http.request(request) 
puts "Request Headers: #{request.to_hash.inspect}" 
puts "Sending PUT #{uri.request_uri} to #{uri.host}:#{uri.port}" 
puts "Response #{response.code} #{response.message}" 
puts "#{response.body}" 
puts "Headers: #{response.to_hash.inspect}" 

그리고 출력 : "

request = Net::HTTP::Put.new("#{uri.request_uri}/test.file") 

오류 수 없습니다 :이에 5 행을 변경할 때

Request Headers: {"accept"=>["*/*"], "host"=>["localhost"], "content-length"=>[88873],  "content-type"=>["multipart/form-data"], "session"=>["AaB03xZZZZZZ11322321111XSDW"], "connection"=>["close"]} 
Sending PUT /dropbox/ to localhost:80 
Response 409 Conflict 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>409 Conflict</title> 
</head><body> 
<h1>Conflict</h1> 
<p>Cannot PUT to a collection.</p> 
<hr /> 
<address>Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.10 with Suhosin-Patch Server at localhost Port 80</address> 
</body></html> 
Headers: {"server"=>["Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.10 with Suhosin-Patch"], "content-length"=>["315"], "content-type"=>["text/html; charset=ISO-8859-1"], "date"=>["Thu, 23 Aug 2012 17:36:40 GMT"], "connection"=>["close"]} 

답변

4

문제가 해결되었다 컬렉션으로 가져 오기 "는 폴더에 대해 업로드를 수행 할 수 없음을 의미합니다. 파일 이름을 지정해야합니다.

관련 문제