我想使用Python在minio中存储和下载文件
以下是代码:
from minio import Minio
import os
def getMinioClient(access, secret):
return Minio(
endpoint="localhost:9000",
access_key=access,
secret_key=secret,
secure=False,
)
if __name__ == "__main__":
client = getMinioClient("admin", "Secret_key123")
try:
file_name = "myfile.csv"
bucket = "file_bucket"
with open(file_name, "rb") as f:
stat_data = os.stat(file_name)
# fput_object to upload file
a = client.fput_object(
bucket,
file_name,
f,
stat_data.st_size
)
print("uploaded")
# using fget_object to download file
client.fget_object(bucket, file_name, f"{file_name}_downloaded")
except Exception as e:
print(e)
我所知道的下载文件的唯一选项是使用fget_object
我如何获取一个链接,将其粘贴到url栏中即可下载所需文件
就像从minio UI获取的链接一样,当我们点击某个文件的共享时,如下所示:
点击共享链接后,会生成一个链接,可以用于下载该文件,甚至无需登录。
我如何通过与minio建立连接来在python代码中生成下载链接。
提前感谢!