是否可以使用 Amazon S3 为选择性用户共享文件

发布于 2024-12-08 10:45:18 字数 181 浏览 0 评论 0原文

我的 S3 存储桶中的文件很少。是否可以与选定的用户共享它们。这些人可能没有 Amazon S3 帐户。我知道如果我将其公开,每个人都可以使用 URL 下载文件。

我想要一个加密的 URL 或一个在被点击时立即要求输入用户名和密码的 URL。

而且我也不想安装任何新的/第三方软件供每个人安装。

谢谢

I have few files in my S3 bucket. Is it possible to share them with selected users. Those people might not have Amazon S3 account. I know if i make it public everyone could able to download the files using URL.

I want something like an encrypted URL or an URL that asks for some Username and password immediately when it is been hit.

And also i do not want to install any new/ third party softwares to be installed by everyone.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑾夏年华 2024-12-15 10:45:18

绝对地。

您可以将文件设为 私有,然后生成 < a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?S3_QSAuth.html" rel="nofollow noreferrer">签名时间到期url 到您的文件。

签名的 URL 是使用您的公钥和密钥生成的,并且设置为在将来的指定时间过期。

根据您使用的技术,使用 AWS 开发工具包

签名网址看起来像:

http://[bucket].s3.amazonaws.com/[key]?AWSAccessKeyId=[AWS_Public_Key]&Expires=1294766482&Signature=[generated_hash]

我在这个答案。

Absolutely.

You can make your files private and then generate time expiring signed urls to your files.

The signed urls are generated using your public key and secret key and are set to expire at a specified time in the future.

Depending on what technology you are using, its probably easiest to generate the urls using one of the AWS SDKS.

Signed urls look something like:

http://[bucket].s3.amazonaws.com/[key]?AWSAccessKeyId=[AWS_Public_Key]&Expires=1294766482&Signature=[generated_hash]

I explain a bit more about these urls in this answer.

岁月苍老的讽刺 2024-12-15 10:45:18

下面是一个示例 ruby​​ 代码,用于为存储桶中的特定位置生成签名 URL。

安装aws-sdk

gem install aws-sdk

创建一个新文件,根据需要命名,我选择shareS3files.rb,请在gist.github.com

#!/usr/bin/env ruby

require 'aws-sdk'
require 'json'

#loading credentials
creds = JSON.load(File.read('secrets.json'))
creds = Aws::Credentials.new(creds['AccessKeyId'], creds['SecretAccessKey'])

#loading config
conf = JSON.load(File.read('config.json'))

# Create a new S3 object
s3 = Aws::S3::Client.new(credentials: creds, region: conf['Region'])

# Create a resource object, simpler to use
resource = Aws::S3::Resource.new(client: s3)
bucket = resource.bucket(conf['Bucket'])

# enumerate every object in a bucket, and create a pre signed url with a 5 days expiration limit
bucket.objects(prefix: 'conf['Location']').each do |obj|
  puts "#{obj.key} => #{obj.object.presigned_url(:get, expires_in: 5 * 24 * 60 * 60)}"
end

现在,创建凭据和配置文件:

secrets.json

{
  "AccessKeyId": "TOCHANGE",
  "SecretAccessKey": "TOCHANGE"
}

config.json

{
  "Region": "TOCHANGE",
  "Bucket": "tochange",
  "Location": "to/change/"
}

进一步的aws和ruby文档:

Here is a sample ruby code to generate signed urls for a particular location in your bucket.

Install aws-sdk:

gem install aws-sdk

Create a new file, name it as you want, I choose shareS3files.rb see it on gist.github.com:

#!/usr/bin/env ruby

require 'aws-sdk'
require 'json'

#loading credentials
creds = JSON.load(File.read('secrets.json'))
creds = Aws::Credentials.new(creds['AccessKeyId'], creds['SecretAccessKey'])

#loading config
conf = JSON.load(File.read('config.json'))

# Create a new S3 object
s3 = Aws::S3::Client.new(credentials: creds, region: conf['Region'])

# Create a resource object, simpler to use
resource = Aws::S3::Resource.new(client: s3)
bucket = resource.bucket(conf['Bucket'])

# enumerate every object in a bucket, and create a pre signed url with a 5 days expiration limit
bucket.objects(prefix: 'conf['Location']').each do |obj|
  puts "#{obj.key} => #{obj.object.presigned_url(:get, expires_in: 5 * 24 * 60 * 60)}"
end

Now, create both credential and configuration files:

secrets.json:

{
  "AccessKeyId": "TOCHANGE",
  "SecretAccessKey": "TOCHANGE"
}

config.json:

{
  "Region": "TOCHANGE",
  "Bucket": "tochange",
  "Location": "to/change/"
}

Further aws and ruby doc:

柠檬色的秋千 2024-12-15 10:45:18

如果您安装了 AWS CLI,则只需使用 presign

aws s3 presign s3://[bucket]/[path_filename]

您还可以将链接设置为在 24 小时内过期 86400 = (60 * 60 * 24))

aws s3 presign s3://[bucket]/[path_filename] --expires-in 86400

If you have the AWS CLI installed you can simply use presign.

aws s3 presign s3://[bucket]/[path_filename]

You can also set the link to expire in 24hrs 86400 = (60 * 60 * 24))

aws s3 presign s3://[bucket]/[path_filename] --expires-in 86400
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文