Javascript 在express Node js中使用multer sftp将文件上载到远程服务器?
我正在尝试使用NodeJS中的multer sftp将文件上传到远程服务器。因为我在看官方文件。以前我将文件上传到AmazonS3而不是远程服务器。现在我想上传文件到远程服务器 API: 上载文件时,返回错误Javascript 在express Node js中使用multer sftp将文件上载到远程服务器?,javascript,node.js,file-upload,remote-server,multer,Javascript,Node.js,File Upload,Remote Server,Multer,我正在尝试使用NodeJS中的multer sftp将文件上传到远程服务器。因为我在看官方文件。以前我将文件上传到AmazonS3而不是远程服务器。现在我想上传文件到远程服务器 API: 上载文件时,返回错误 2017-11-10T02:39:48.297Z - debug: Error Occured {"code":"ENOTFOUND","errno":"ENOTFOUND", "syscall":"getaddrinfo","hostname":"http://www.port*
2017-11-10T02:39:48.297Z - debug: Error Occured {"code":"ENOTFOUND","errno":"ENOTFOUND",
"syscall":"getaddrinfo","hostname":"http://www.port****es.in/","host":"http://www.port****es.in/",
"port":22,"level":"client-socket","storageErrors":[]}
而且22号端口在我的域中是开放的。等待建议,
提前感谢。对于您的错误,有两种可能
multer sftp
将文件上传到远程服务器是一种简单而灵活的方式。
我们还可以在NodeJS中使用scp、ssh技术将文件上传到远程服务器
工作代码:
exports.newFileUpload = function(req , res , next){
var storage = sftpStorage({
sftp: {
host: 'hostname',
port: 22,
username: 'username',
password: 'password'
},
destination: function (req, file, cb) {
cb(null, 'images/')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
})
var upload = multer({ storage: storage }).array('file');
upload(req,res,function(err){
logger.debug(JSON.stringify(req.body));
logger.debug(JSON.stringify(req.files));
if(err){
logger.debug("Error Occured", JSON.stringify(err));
res.json({error_code:1,err_desc:err});
} else{
logger.debug("Files uploaded successfully");
res.json({error_code:0,err_desc:null});
}
});
}
注意:使用“multer sftp”时,远程服务器中的端口号22是打开的
希望有帮助
主机
不应具有http://
。正确的方法:host:'www.port****es.in',
@mukeshharma我也试过,但错误相同
exports.newFileUpload = function(req , res , next){
var storage = sftpStorage({
sftp: {
host: 'hostname',
port: 22,
username: 'username',
password: 'password'
},
destination: function (req, file, cb) {
cb(null, 'images/')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
})
var upload = multer({ storage: storage }).array('file');
upload(req,res,function(err){
logger.debug(JSON.stringify(req.body));
logger.debug(JSON.stringify(req.files));
if(err){
logger.debug("Error Occured", JSON.stringify(err));
res.json({error_code:1,err_desc:err});
} else{
logger.debug("Files uploaded successfully");
res.json({error_code:0,err_desc:null});
}
});
}