我正在尝试使用lambda将文件从s3发送到azure。但它超时并仅上传15B。
'use strict';
var AWS = require('aws-sdk');
var azure = require('azure-storage');
var s3 = new AWS.S3();
var xml2js = require('xml2js');
var parser = new xml2js.Parser({explicitArray : false});
var extractedData = "";
exports.handler = function(event, context) {
var bucketName = event.Records[0].s3.bucket.name;
var keyName = event.Records[0].s3.object.key;
readFile(bucketName, keyName, readFileContent, onError);
};
function readFile (bucketName, filename, onFileContent, onError) {
var params = { Bucket: bucketName, Key: filename };
s3.getObject(params, function (err, data) {
if (!err)
onFileContent(filename, data.Body);
else
console.log(err);
});
}
function readFileContent(filename, content) {
parser.parseString(content, function(err,result){
console.log(result);
var fileService = azure.createFileService('fgdgdfg','dfgdfgdfgdfgdfg');
fileService.createFileFromText('xfiles', '', 'rros.json', result, function(error, result, response) {
if (!error) {
console.log("file created....")
}else{
console.log(error)
}
});
});
}
function onError (err) {
console.log('error: ' + err);
}
错误:
TypeError:第一个参数必须是字符串或缓冲区 在ClientRequest.OutgoingMessage.write(_http_outgoing.js:458:11) 在Request.write(/var/task/node_modules/request/request.js:1501:27)
答案 0 :(得分:0)
函数createFileFromText(...)
的第四个参数不接受JavaScript对象。您应该使用JSON.stringify()
将其转换为如下字符串:
fileService.createFileFromText('xfiles', '', 'rros.json', JSON.stringify(result), function(error, result, response) {
if (!error) {
console.log("file created....")
}else{
console.log(error)
}
});