Node.js S3和Couchbase-如何从Amazon获取文件并存储?
我试图从S3获取一个文件,并将其存储在NoSQL Couchbase中 我正在尝试使用以下代码存储outputStream:Node.js S3和Couchbase-如何从Amazon获取文件并存储?,node.js,amazon-s3,couchbase,Node.js,Amazon S3,Couchbase,我试图从S3获取一个文件,并将其存储在NoSQL Couchbase中 我正在尝试使用以下代码存储outputStream: var outputStream1 = fs.createWriteStream("./tmp/" + url); // if statusCode == 200, then we have the file, lets save it in out cache and then send it to the client
var outputStream1 = fs.createWriteStream("./tmp/" + url);
// if statusCode == 200, then we have the file, lets save it in out cache and then send it to the client
res.on('data', function (chunk) {
outputStream1.write(chunk);
});
res.on('end', function () {
var value = outputStream1;
cb.set(key, value, function (err, result) {
if (err) { console.log(err); }
console.log("Set item for key with CAS: " + result.cas);
cb.get(key, function (err, result) {
if (err) { console.log(err); }
console.log("Value for key is: " + result.value);
var readStream = result.value;
readStream.on('open', function () {
console.log(response);
});
readStream.on('end', function () {
readStream.close();
});
});
});
问题是我存储了outputStream,然后试图读取它
我寻找一种方法,将从S3获得的数据对象存储在Couchbase中,然后能够将其发送到客户端。可能吗 我认为您可以将缓冲区设置为值,稍后再获取该值。首先,您需要将数据保存在缓冲区中:
var buffers = [];
res.on('data', function (chunk) {
buffers.push(chunk);
});
res.on('end', function () {
var value = Buffer.concat(buffers);
cb.set(key, value, function (err, result) {
if (err) { console.log(err); }
console.log("Set item for key with CAS: " + result.cas);
cb.get(key, function (err, result) {
if (err) { console.log(err); }
console.log("Value for key is: " + result.value); // You should get your value in here });
});
您也可以使用模块来帮助您