Skip to content

Commit d6702d2

Browse files
authoredOct 16, 2019
Add files via upload
1 parent 9281cb8 commit d6702d2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

Diff for: ‎convert.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import requests
4+
import os,json
5+
6+
from requests_toolbelt import MultipartEncoder
7+
8+
url = "http://localhost/unoconv/pdf"
9+
10+
def post_file(url,path):
11+
filename = os.path.basename(path)
12+
convert_name = str(filename).split('.')[0] + '.pdf'
13+
14+
m = MultipartEncoder(
15+
fields= {
16+
'file':(filename,open(path,'rb')),
17+
}
18+
)
19+
response = requests.request('POST', url, data=m, headers={'Content-Type':m.content_type})
20+
21+
with open(convert_name, 'wb') as f:
22+
f.write(response.content)
23+
24+
return convert_name
25+
26+
path = "./demo.docx"
27+
28+
ret = post_file(url, path)
29+
print(ret)
30+

0 commit comments

Comments
 (0)
Please sign in to comment.