Notice
Recent Posts
Recent Comments
Link
아미(아름다운미소)
[PYTHON] MULTIPART FILE UPLOAD 본문
파일 업로드 api 연동을 할 때 java의 경우는 form을 만들어서 multipart 옵션을 추가해서
이것저것 복잡한 작업을 거쳐야 하는데 python의 경우 urllib2 module을 이용하면 간편하게 연동을 할 수 있습니다.
python2.7 기준
upload_test.asp
이것저것 복잡한 작업을 거쳐야 하는데 python의 경우 urllib2 module을 이용하면 간편하게 연동을 할 수 있습니다.
python2.7 기준
from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 def HTTP_GLOB_transfer(url, filename, attachFileNM): try: register_openers() datagen, headers = multipart_encode({attachFileNM : open(unicode(filename, 'utf-8'), 'rb')}) request = urllib2.Request(url, datagen, headers) urllib2.urlopen(request).read() except Exception as error: print(str(error)) if __name__ == '__main__': HTTP_GLOB_transfer('http://www.test.co.kr/upload_test.asp','D:/Data/파일.wav','attachfile')
Set theForm = Server.CreateObject("ABCUpload4.XForm") theForm.AbsolutePath = True theForm.Overwrite = True Set theField = theForm.item("attachFile")(1) If theField.FileExists Then theField.Save "D:\wwwroot\data\" & theField.safeFileName Response.Write "파일전송완료." Else Response.Write "파일전송실패." End If
'랭귀지 > python' 카테고리의 다른 글
python filter (0) | 2019.04.03 |
---|---|
python with open을 써서 파일을 여러 개 open하는 법 (0) | 2019.04.02 |
Consider using the `--user` option or check the permissions. (0) | 2019.03.25 |
Python3 내장 자료형 (0) | 2019.03.05 |
PyWin32 - Win32 API 사용을 위한 파이썬 확장 (0) | 2019.03.04 |
Comments