用lambda生成的预设URL在S3存储桶上托管的文件的用户下载
我正在尝试拥有一个用户输入某个字符串的网站,并且基于该字符串,我返回一个匹配文件供用户下载。目前,我已经设置了它,以便有一个可以进行匹配的lambda函数,并且网页通过API网关与Lambda功能进行了对话。 lambda函数的结果是动态生成的预先定义URL,有效期为一个小时。
到目前为止,我的代码下载了一个文件(filename.json),该文件是一行,只包含预先符号的URL(引号),然后我必须打开该文件以获取链接,然后手动将其放在我的浏览器中。有没有办法修改此代码直接下载S3托管文件?我删除了确切的链接,并用********替换了一部分。
fetch("https://********.execute-api.us-east-1.amazonaws.com/test", requestOptions)
.then((res) => { return res.blob(); })
.then((data) => {
var a = document.createElement("a");
a.href = window.URL.createObjectURL(data);
a.download = "FILENAME";
a.click();
})
I'm trying to have a website where the user inputs a certain string, and based on that string I return a matching file for the user to download. Currently I have it set up so that there is a lambda function that does the matching, and the webpage talks to the lambda function via API gateway. The result of the lambda function is a dynamically generated presigned URL which is valid for one hour.
So far I have code that downloads a file (FILENAME.json) which is one line and just contains the presigned URL (in quotes), which I would then have to open to get a link and then manually place it in my browser. Is there a way to modify this code to directly download the S3-hosted file? I've removed the exact link and replaced a part of it with ********.
fetch("https://********.execute-api.us-east-1.amazonaws.com/test", requestOptions)
.then((res) => { return res.blob(); })
.then((data) => {
var a = document.createElement("a");
a.href = window.URL.createObjectURL(data);
a.download = "FILENAME";
a.click();
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过于复杂的事情。以下作用很好:
I was overcomplicating things. The following works just fine: