Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码更新建议 #20

Open
pikpiksec opened this issue Nov 11, 2022 · 1 comment
Open

代码更新建议 #20

pikpiksec opened this issue Nov 11, 2022 · 1 comment

Comments

@pikpiksec
Copy link

对于现版本typora,其文件路径中中文汉字会被url编码,导致无法上传图片。
由此建议将文件上传接口中的图片路径进行url解码

from urllib.parse import unquote

async def upload_img(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

@dongfanger
Copy link
Owner

@pikpiksec 欢迎提pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants