Skip to content

代码更新建议 #20

Open
Open
@pikpiksec

Description

@pikpiksec

对于现版本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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions