0
我的客戶端在S3上存儲了大量映像。我們需要將這些圖像作爲迴應。這裏是我寫的代碼:NodeJS:從AWS S3存儲桶獲取映像
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: "AccessKey",
secretAccessKey: "SecretAccessKey"
});
var s3 = new AWS.S3();
s3.getObject({ Bucket: "BucketName", Key: "ImageURL" },
function(error, data) {
if (error != null) {
var _length = data.Body.length;
//Execution freezes here. Don't get any response.
res.writeHead(200, {
'Content-Type': 'image/jpeg',
'Content-Length': _length
});
res.end(new Buffer(data.Body, 'binary'));
}
}
);
我們如何得到圖像的迴應?
'//執行凍結在這裏.'你沒有'else'塊。爲什麼你把'if(error!= null)'當作......成功呢?你沒有邏輯倒退嗎? –