更新MinIO文件上传逻辑,修改上传文件名和路径;调整文件选择路径以支持新的目录结构
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| from minio import Minio | from minio import Minio | ||||||
| from minio.error import S3Error | from minio.error import S3Error | ||||||
| import os | import os | ||||||
|  | from datetime import timedelta | ||||||
| MINIO_HOST=os.getenv("MINIO_HOST", "127.0.0.1") | MINIO_HOST=os.getenv("MINIO_HOST", "127.0.0.1") | ||||||
|  |  | ||||||
| MINIO_CONFIG = { | MINIO_CONFIG = { | ||||||
| @@ -85,8 +86,8 @@ minio_client= get_minio_client() | |||||||
|  |  | ||||||
| # 要上传的存储桶信息 | # 要上传的存储桶信息 | ||||||
| bucket_name = "my-bucket"  # 替换为你的存储桶名称 | bucket_name = "my-bucket"  # 替换为你的存储桶名称 | ||||||
| object_name = "my-file.txt"  # 文件在MinIO中存储的名称 | object_name = "1.jpg"  # 文件在MinIO中存储的名称 | ||||||
| file_path = "./ragflow.txt"  # 本地文件路径 | file_path = "G:\\11\\ragflow_api_test\\2.jpg"  # 本地文件路径 | ||||||
|  |  | ||||||
| try: | try: | ||||||
|     # 检查存储桶是否存在,如果不存在则创建(可选) |     # 检查存储桶是否存在,如果不存在则创建(可选) | ||||||
| @@ -100,6 +101,10 @@ try: | |||||||
|         object_name=object_name, |         object_name=object_name, | ||||||
|         file_path=file_path |         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) | ||||||
|  |     print(res) | ||||||
|     print(f"文件 '{file_path}' 成功上传到存储桶 '{bucket_name}' 为 '{object_name}'") |     print(f"文件 '{file_path}' 成功上传到存储桶 '{bucket_name}' 为 '{object_name}'") | ||||||
|      |      | ||||||
| except S3Error as exc: | except S3Error as exc: | ||||||
|   | |||||||
| @@ -71,7 +71,7 @@ def pair_pdf_and_txt(pdf_path, txt_path): | |||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|  |  | ||||||
|     file_path = "g:\\11\\22\\" |     file_path = "g:\\11\\22\\路桥设计党建\\" | ||||||
|     pdf_dict, txt_dict = pair_pdf_and_txt(file_path,file_path) |     pdf_dict, txt_dict = pair_pdf_and_txt(file_path,file_path) | ||||||
|  |  | ||||||
|     if not pdf_dict: |     if not pdf_dict: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user