如何使用提供的 url 从 s3 下载文件? [英] How to download a file from s3 using provided url?

查看:65
本文介绍了如何使用提供的 url 从 s3 下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我将获得 s3 文件的网址,例如:https://s3.amazonaws.com/account-update/input.csv我必须下载它然后处理它.我已经做了什么:

In my application I will get the url of s3 file like : https://s3.amazonaws.com/account-update/input.csv I have to download it and then process it. What I already done :

AmazonS3 s3 = new AmazonS3Client(credentials);
S3Object s3object = s3.getObject(new GetObjectRequest(
bucketName, key));

我可以通过提供存储桶名称和密钥来下载文件,但是如何使用 url(https://s3.amazonaws.com/account-update/input.csv) 仅?

I am able to download the file by providing bucket name and key, but how can I download the file using the url(https://s3.amazonaws.com/account-update/input.csv) only?

推荐答案

您可以通过标准 curl/wget 下载文件,就像您从 Internet 下载任何其他文件一样.

You could download the file via a standard curl/wget, the same as you would download any other file off the Internet.

然而,重要的部分是允许从 Amazon S3 访问对象.几个选项:

The important part, however, is to enable access to the object from Amazon S3. A few options:

  • 使对象公开可读:这可以通过控制台或 CLI/API 来完成.但是,任何拥有该网址的人都可以下载它.
  • 创建Amazon S3 存储桶策略 授予对所需文件/目录/存储桶的读取访问权限.但是,同样,拥有该 URL 的任何人都可以访问这些对象.
  • 保持对象私有,但使用预签名URL 向 URL 添加参数以证明您可以下载该对象.这个预先签名的 URL 是有时间限制的,可以使用当前的 AWS 凭证通过几行代码生成.
  • Make the object publicly-readable: This can be done via the console or CLI/API. However, anyone with that URL will be able to download it.
  • Create an Amazon S3 Bucket Policy that grants read access for the desired file/directory/bucket. But, again, anyone with the URL will be able to access those objects.
  • Keep the object private, but use a pre-signed URL that adds parameters to the URL to prove that you are permitted to download the object. This pre-signed URL is time-limited and can be generated with a few lines of code using current AWS credentials.

这篇关于如何使用提供的 url 从 s3 下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆