可直接使用的脚本
小于 1 分钟
typora自定义文件上传
安装依赖
pip install uuid Minio
import sys
import time
from pathlib import Path
import uuid,os
from minio import Minio
from minio.error import S3Error
base_url = "127.0.0.1:9000"
bucket_name = "web"
year_month = time.strftime("%Y/%m") # 2026/06
client = Minio(
"127.0.0.1:9000",
access_key="minio",
secret_key="password",
secure=False
)
def upload(name:str,path:str):
try:
result = client.fput_object(
bucket_name=bucket_name,
object_name=f"{year_month}/{name}",
file_path=path,
)
return f"http://{base_url}/{bucket_name}/{result.object_name}"
except S3Error as e:
print(f"文件上传失败:{e}")
return ""
upload_path = sys.argv[1:]
for image_url in upload_path:
ext = Path(image_url).suffix
url = upload(f"{uuid.uuid4()}{ext}",str(Path(image_url)))
print(url)
结果:http://127.0.0.1:9000/web/2026/08/facdd0ac-7c2d-4f2f-931a-352e65f047ff.png

