从客户端下载AWS S3文件 [英] AWS S3 File Download from the client-side

查看:206
本文介绍了从客户端下载AWS S3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用前端的按钮从s3存储桶下载文件.如何做到这一点?我对如何开始这件事一无所知.我已经尝试过研究,但是没有运气-我搜索的所有内容都是关于 UPLOADING 文件到s3存储桶中,而不是 DOWNLOADING 文件.提前致谢.

I am currently trying to download the file from the s3 bucket using a button from the front-end. How is it possible to do this? I don't have any idea on how to start this thing. I have tried researching and researching, but no luck -- all I have searched are about UPLOADING files to the s3 bucket but not DOWNLOADING files. Thanks in advance.

注意:我正在将其应用于 ReactJS(Frontend) NodeJS(Backend),而且该文件是使用Webmerge上传的

NOTE: I am applying it to ReactJS (Frontend) and NodeJS (Backend) and also, the file is uploaded using Webmerge

更新:我正在尝试与此生成一个下载链接(即使我不是后端开发者,也尝试过节点)(lol)

UPDATE: I am trying to generate a download link with this (Tried node even if I'm not a backend dev) (lol)

查看下面的图片

到目前为止我已经尝试过的

onClick函数

推荐答案

如果您要下载的文件不是公开的,则必须创建一个签名的url来获取该文件.

If the file you are trying to download is not public then you have to create a signed url to get that file.

解决方案在这里从亚马逊下载文件的Javascripts3存储桶?获取非公开文件,该过程围绕创建一个lambda函数,该函数将为您生成一个已签名的url,然后使用该url单击按钮下载文件.

The solution is here Javascript to download a file from amazon s3 bucket? for getting non public files, which revolves around creating a lambda function that will generate a signed url for you then use that url to download the file on button click

但是,如果您要下载的文件是公开的,则不需要签名的URL,只需要知道文件的路径即可,这些URL的结构如下:

BUT if the file you are trying to download you is public then you don't need a signed url, you just need to know the path to the file, the urls are structured like: https://s3.amazonaws.com/ [file path]/[filename]

它们还被AWS团队放大和创建.

They is also aws amplify its created and maintain by AWS team.

只需遵循入门,然后从您的react应用下载文件就是这样:

Just follow Get started and downloading the file from your react app is simply as:

Storage.get('hello.png', {expires: 60})
.then(result => console.log(result))
.catch(err => console.log(err));

这篇关于从客户端下载AWS S3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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