生成一个链接,该链接从Python中的Minio下载文件
我想使用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 bar粘贴后,该链接获取所需的文件下载
就像我们从Minio UI获得的链接一样,当我们单击特定文件的共享时,如下面的
单击共享链接后,生成了一个链接,可用于下载该文件而无需登录即可下载该文件。
我将如何通过与Minio建立连接来从Python代码中生成下载链接。
提前致谢!
I want to use python to store and download file in minio
Below is the code
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)
Only option I know to download file is using fget_object
How can I get a link, which upon pasted in url bar get the required file downloaded
Just like link which we get from minio UI, when we click on share of particular file like below
After clicking on share link, a link is generated which can be used to download that file without even logging in.
How will I be able to generate the download link from within python code by making connection to minio.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个名为get_presigned_url的方法,该方法创建用于删除,更新或下载文件的URL。请参阅 /linux/developers/python/api.html#get_presigned_url
用于下载目的:
There is a method named get_presigned_url that create url for deleting, updating or downloading file. See more at https://min.io/docs/minio/linux/developers/python/API.html#get_presigned_url
For downloading purpose:
首先,您必须将公共政策设置为您的存储桶
您可以使用以下示例
,然后可以使用从存储桶名和文件名来生成文件路径。
at first you must set public policy to your bucket
you can use the following example
and then you can use from bucket name and file name to generate your file path.