Skip to content

Commit

Permalink
修复无法上传中文文件的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shuoGG1239 committed Mar 19, 2019
1 parent c7d138e commit 0f3e1d0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions util/sm_util.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import requests
import json
import os
import urllib

import requests


def upload_img(image_path):
files_map = [('smfile', image_path)]
file_name = os.path.split(image_path)[1]
params = {
'ssl': False,
'format': 'png'
}
multi_files = list(map(lambda x: (x[0], (os.path.split(x[1])[1], open(x[1], 'rb'))), files_map))
multi_files = list(map(lambda x: (x[0], (urllib.parse.quote(os.path.split(x[1])[1]), open(x[1], 'rb'))), files_map))
resp = requests.post("https://sm.ms/api/upload", data=params, files=multi_files)
print(resp.text)
result = json.loads(resp.text)
if result['code'] == 'success':
view_url = result['data']['url']
del_url = result['data']['delete']
file_name = result['data']['filename']
resp_dict = {'url': view_url, 'delete': del_url, 'filename': file_name, 'success': True}
print(view_url)
print(del_url)
Expand Down

0 comments on commit 0f3e1d0

Please sign in to comment.