更新MinIO文件上传逻辑,修改上传文件名为带路径格式;添加上传文件时的注释说明

This commit is contained in:
2025-07-10 22:38:09 +08:00
parent 29d9b44e0a
commit 94fee102f3
2 changed files with 258 additions and 2 deletions

View File

@@ -86,9 +86,17 @@ minio_client= get_minio_client()
# 要上传的存储桶信息
bucket_name = "my-bucket" # 替换为你的存储桶名称
object_name = "1.jpg" # 文件在MinIO中存储的名称
object_name = "image/1.jpg" # 文件在MinIO中存储的名称
file_path = "G:\\11\\ragflow_api_test\\2.jpg" # 本地文件路径
# 通过fput_object上传时
# 如果object_name为image\image.jpg则上传后的名字就是image\image.jpg
# 如果object_name为image/image.jpg则上传后image为文件夹文件名为image.jpg
try:
# 检查存储桶是否存在,如果不存在则创建(可选)
if not minio_client.bucket_exists(bucket_name):
@@ -101,9 +109,13 @@ try:
object_name=object_name,
file_path=file_path
)
# 获取文件的预签名URL可选
res = minio_client.get_presigned_url("GET", bucket_name, object_name, expires=timedelta(days=7))
#res=minio_client.share_file(bucket_name, object_name, 7)
#res = "http://127.0.0.1:9000" + "/"+bucket_name+"/" + object_name
print(res)
print(f"文件 '{file_path}' 成功上传到存储桶 '{bucket_name}''{object_name}'")