我正在尝试在s3中获取存储桶的数据,但是它不起作用。 我想将数据作为getFiles中的返回值(例如,Observables) 你有个好主意吗?
getFiles() {
const avro = require("avsc");
const params = {
Bucket: this.BUCKET,
Key: this.key
};
this.test = this.getS3Bucket().getObject(params, function(err, data) {
if (err) {
console.log("There was an error : " + err);
return;
}
return data;
});
return this.test;
}
答案 0 :(得分:0)
这对我有用
var AWS = require('aws-sdk');
let spacesEndpoint = new AWS.Endpoint(process.env.S3_BUCKET_ENDPOINT);
var credentials = {
endpoint: spacesEndpoint,
accessKeyId:process.env.S3_BUCKET_KEY ,
secretAccessKey: process.env.S3_BUCKET_SECRET,
region: process.env.S3_BUCKET_REGION
};
var s3 = new AWS.S3(credentials);
var params = { Bucket: process.env.S3_BUCKET_NAME, Key: File_name };
getObject(params , function(err, data) {
if (err) {
console.log(err);
}
else {
res.send(data);
}
});