2010-08-16 6 views
2

python을 사용하여 이미지 파일을 업로드 할 수있는 방법이 있습니까? 내가 아래 python.But 코드로 구성된 간단한 HTML 페이지에서 파일을 업로드 할 수있는 파이썬 프로그램에서 할 수있게하고 싶습니다. 그것은 urllib2 모듈을 사용하여 완료 될 수 있습니까? 내가 볼 수있는 모든 예가 있나?python을 사용하여 이미지 파일 업로드

도와주세요. 감사합니다.

<form action="http://somesite.com/handler.php" method="post" enctype="multipart/form-data"> 

<table> 

     <tr><td>File:</td><td><input type="file" name="file" /></td></tr> 

     <tr><td><input type="submit" value="Upload" /></td></tr> 

</table> 

</form> 
+1

무엇? 'handler.php'의 버전을 원하십니까? 비슷한 질문을 했습니까? 수많은 질문은 당신과 동일합니다. –

+0

[python 스크립트를 통해 파일 업로드] 가능한 중복 (0120-327-002) –

답변

5

당신은 그것을 위해 pycurl 패키지를 사용할 수 있습니다.

from StringIO import StringIO 
from pycurl import * 
c = Curl() 
d = StringIO() 
h = StringIO() 
c.setopt(URL, "http://somesite.com/handler.php") 
c.setopt(POST, 1) 
c.setopt(HTTPPOST, [('file', (FORM_FILE, '/path/to/file')), ('submit', 'Upload')]) 
c.setopt(WRITEFUNCTION, d.write) 
c.setopt(HEADERFUNCTION, h.write) 
c.perform() 
c.close() 
+0

pycurl을 사용하는 파일 대신 메모리에서 이진 데이터를 게시 할 수 있습니까? – Naveen

관련 문제