Add files via upload

This commit is contained in:
Jimmy Xiang
2019-10-16 11:27:37 +08:00
committed by GitHub
parent 9281cb885a
commit d6702d2071

30
convert.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python3
import requests
import os,json
from requests_toolbelt import MultipartEncoder
url = "http://localhost/unoconv/pdf"
def post_file(url,path):
filename = os.path.basename(path)
convert_name = str(filename).split('.')[0] + '.pdf'
m = MultipartEncoder(
fields= {
'file':(filename,open(path,'rb')),
}
)
response = requests.request('POST', url, data=m, headers={'Content-Type':m.content_type})
with open(convert_name, 'wb') as f:
f.write(response.content)
return convert_name
path = "./demo.docx"
ret = post_file(url, path)
print(ret)