在 Node.js 项目中,我试图从 S3获取数据。
当我使用 getSignedURL
时,一切都正常:
aws.getSignedUrl('getObject', params, function(err, url){
console.log(url);
});
我的参数是:
var params = {
Bucket: "test-aws-imagery",
Key: "TILES/Level4/A3_B3_C2/A5_B67_C59_Tiles.par"
如果我把 URL 输出到控制台并粘贴到 Web 浏览器中,它就会下载我需要的文件。
然而,如果我尝试使用 getObject
,我会得到各种奇怪的行为。我想我只是用错了。这是我试过的方法:
aws.getObject(params, function(err, data){
console.log(data);
console.log(err);
});
产出:
{
AcceptRanges: 'bytes',
LastModified: 'Wed, 06 Apr 2016 20:04:02 GMT',
ContentLength: '1602862',
ETag: '9826l1e5725fbd52l88ge3f5v0c123a4"',
ContentType: 'application/octet-stream',
Metadata: {},
Body: <Buffer 01 00 00 00 ... > }
null
So it appears that this is working properly. However, when I put a breakpoint on one of the console.log
s, my IDE (NetBeans) throws an error and refuses to show the value of data. While this could just be the IDE, I decided to try other ways to use getObject
.
aws.getObject(params).on('httpData', function(chunk){
console.log(chunk);
}).on('httpDone', function(data){
console.log(data);
});
This does not output anything. Putting a breakpoint in shows that the code never reaches either of the console.log
s. I also tried:
aws.getObject(params).on('success', function(data){
console.log(data);
});
但是,这也不会输出任何东西,放置断点表明从未到达 console.log
。
我做错了什么?