我试图弄清楚如何在 S3 上执行相当于 fs.exists() 的操作。
我成功获取了存储桶的内容,但我不知道如何询问 S3 存储桶中是否存在特定文件(我不想下载整个文件列表并检查客户端,因为也有许多文件)。
var s3 = require('aws2js').load('s3', appConfig.awsAccessKeyId, appConfig.awsSecretAccessKey);
s3.setBucket(appConfig.awsBucketName);
var folder = encodeURI('reports');
var url = '?prefix=' + folder;
s3.get(url,{Contents: null, Key: 'reports/emot_cat_r1180341142.png'},'xml', function (error, data) {
console.log("Error",error);
console.log("Data",data);
true.should.be.true;
done();
});
输出
{名称:'umusergen',前缀:'reports',标记:{},MaxKeys:'1000',IsTruncated:'false',内容:[ {键:'reports/',LastModified:'2013-06-16T17: 44:25.000Z',ETag:'"d41d8cd98f00b204e9800998ecf8427e"',大小:'0',所有者:[对象],存储类:'标准'},{键:'reports/emot_cat_r1180341142.png',LastModified:'2013-06 -16T23:18:59.000Z',ETag:'"0b04aa9146d36a447019b1aa94be7eb3"',大小:'26374',所有者:[对象],存储类:'标准'},{键:'reports/polarity_r1180341142.png',LastModified:' 2013-06-16T23:19:00.000Z',ETag:'"22fd521e0a5e858040082d0d47078532"',大小:'23091',所有者:[对象],存储类:'标准'},{键:'reports/wordcloud_r1180341142.png',LastModified:'2013-06-16T23:19:07.000Z', :'“9f7ee9d2fdce5f460b2c42444edd6efc”',大小:'167164',所有者:[对象],存储类:'标准'}],'@':{ xmlns:{ xmlns:'存储类:'标准'}],'@':{ xmlns:{ xmlns:'存储类:'标准'}],'@':{ xmlns:{ xmlns:'http://s3.amazonaws.com/doc/2006-03-01/ ' } } }
“{Contents: null, Key: '[file path/name]'}”是我试图解释上面引用的 API 指令。
如您所见,它只是枚举存储桶的内容,但我需要调用 API 来检查特定文件是否存在。
任何人都可以帮忙吗?我对这一切都很陌生。