我的目标:
显示一个对话框,提示用户保存从aws下载的文件.
我的问题:
我目前正在使用awssum-amazon-s3来创建下载流.但是我只是设法将文件保存到我的服务器或将其流式传输到命令行......正如您从我的代码中看到的,我最后的尝试是尝试手动设置失败的内容处置标头.我不能使用res.download(),因为标题已经设置好了?
我怎样才能实现目标?
我的节点代码:
app.post('/dls/:dlKey', function(req, res, next){
// download the file via aws s3 here
var dlKey = req.param('dlKey');
Dl.findOne({key:dlKey}, function(err, dl){
if (err) return next(err);
var files = dl.dlFile;
var options = {
BucketName : 'xxxx',
ObjectName : files,
};
s3.GetObject(options, { stream : true }, function(err, data) {
// stream this file to stdout
fmt.sep();
data.Headers['Content-Disposition'] = 'attachment';
console.log(data.Headers);
data.Stream.pipe(fs.createWriteStream('test.pdf'));
data.Stream.on('end', function() {
console.log('File Downloaded!');
});
});
});
res.end('Successful Download Post!');
});
Run Code Online (Sandbox Code Playgroud)
我的角度代码:
$scope.dlComplete = …Run Code Online (Sandbox Code Playgroud) 我试图在函数执行期间写入和读取 lambda 中的 /temp dir,我知道最好的方法是使用 S3,但对于这个项目,我必须使用节点文件系统
const fs = require('fs');
exports.handler = async (event) => {
const path = '/tem/hi.json';
const write = (file) => {
fs.writeFile(file, "Hello World!", function(err) {
if (err) return console.log(err);
return {
statusCode:200,
body:JSON.stringify('data was written')
};
});
};
return write(path);
};
Run Code Online (Sandbox Code Playgroud)