我正在尝试直接从浏览器中从 S3 下载文件。我正在使用AWS Javascript SDK和NodeJS + Webpack。
我可以发出 GetObject 请求,并且可以在"开发人员工具"视图中看到浏览器 (Chrome( 下载字节。
我在响应中将"内容处置"标头设置为:
Content-Disposition:attachment; filename="A1.jpeg"
但是,我没有看到"另存为"对话框或在我的文件系统(在"下载"文件夹中(中创建的任何文件。字节去哪里?
如何将数据保存在文件中?
这是我的代码:
var getObject = function getObject(bucketName, fileName) {
var params = {
Bucket: bucketName,
Key: fileName,
ResponseContentDisposition: 'attachment; filename="' + fileName + '"'
};
return s3.getObject(params).promise();
}
getObject(BUCKET_NAME, item)
.then(
function (getFileResponse) {
console.log(" file downloaded.. " );
}
,
function(error) {
// Common error handling
console.log(" error = " + error);
})
我以前遇到过这种情况,然后我使用了"s3.getSignedUrl"函数而不是"s3.getObject",如下所示:
s3.getSignedUrl('putObject',s3Params).then(function(url){
//the returned "url" used by the browser to download
},function(error){
//Error handling
})
并且 s3Params 将包含(Buckey,键"对象名称"等(