var uploadLogoAdImage = function (req, res) {
var appName = req.params.appName;
var ftpEndPointPath = '${com.wowza.wms.context.VHostConfigHome}/content/';
var s3_bucket = 'w-a-images';
var uploadParams = {
Bucket: s3_bucket,
Key: '',
Body: '',
ACL: 'public-read'
};
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploadTemp/');
},
filename: function (req, file, cb) {
var datetimestamp = Date.now();
cb(null, file.originalname.split('.')[file.originalname.split('.').length - 2] + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length - 1]);
}
});
var upload = multer({
storage: storage
}).single('file');
upload(req, res, function (err) {
console.log(req.file);
if (err) {
res.json({ error_code: 1, err_desc: err });
return;
}
var filePathStr = req.file.path;
var splitter = filePathStr.toString().split('\\');
var fileName = splitter[1];
var file = filePathStr;
var fileStream = fs.createReadStream(file);
var read_file = fs.readFileSync(file);
fileStream.on('error', function (err) {
console.log('File Error', err);
});
var client = new Client();
var ftpConfig = {
host: '13.126.230.30',
port: 21,
user: 'wftp',
password: 'xxxxxxxxx'
}
client.connect(ftpConfig);
uploadParams.Body = fileStream;
uploadParams.Key = 'l_ads/' + path.basename(file);
s3.upload(uploadParams, (err, data) => {
if (err) {
console.log("Error", err);
}
if (data) {
console.log(data);
}
});
client.on('ready', function () {
client.put(filePathStr, './' + fileName, function (ftpErr) {
if (ftpErr) {
console.log(ftpErr);
} else {
client.end();
res.status(200).json({
message: 'success',
videoUrl: 'https://wowstream-ads-images.s3.ap-south-1.amazonaws.com/' + uploadParams.Key,
ftpPath: ftpEndPointPath + fileName,
fileSize: req.file.size,
fileName: fileName
});
}
});
});
});
};
错误:
events.js:183 投掷者//未处理的“错误”事件 ^
Error: connect ECONNREFUSED 13.126.230.30:21
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
Waiting for the debugger to disconnect...
[nodemon] app crashed - waiting for file changes before starting...
我尝试了所有方法,但仍然遇到相同的错误。我安装了新版本的fs软件包和图标脚本,都无法正常工作。在上传了S3文件之后,我没有得到正确的响应。
我尝试了所有这些事情,无论他们怎么说,我都不明白错误的出处。数据存储在s3中,然后抛出事件未处理的错误。有时连接拒绝,有时会出现超时错误。
两天以来,我尝试了所有方法,但没有得到任何解决方案