Open pikpiksec opened 1 year ago
对于现版本typora,其文件路径中中文汉字会被url编码,导致无法上传图片。 由此建议将文件上传接口中的图片路径进行url解码
from urllib.parse import unquote
async def uploadimg(path): """上传图片""" path = unquote(path, 'utf-8') # 此处添加url解码 name = os.path.basename(path) , suffix = os.path.splitext(name) print(f"正在上传{name}") with open(path, 'rb') as f: file = { "bits": f.read(), "name": name, "type": mime_mapping[suffix] } url = server.metaWeblog.newMediaObject(conf["blog_id"], conf["username"], conf["password"], file) return url
@pikpiksec 欢迎提pr
对于现版本typora,其文件路径中中文汉字会被url编码,导致无法上传图片。 由此建议将文件上传接口中的图片路径进行url解码
from urllib.parse import unquote
async def uploadimg(path): """上传图片""" path = unquote(path, 'utf-8') # 此处添加url解码 name = os.path.basename(path) , suffix = os.path.splitext(name) print(f"正在上传{name}") with open(path, 'rb') as f: file = { "bits": f.read(), "name": name, "type": mime_mapping[suffix] } url = server.metaWeblog.newMediaObject(conf["blog_id"], conf["username"], conf["password"], file) return url