Multer-sftp module is not including in the server script and after running server script i am getting timeout error.

const express = require('express');
const multer = require('multer');
const sftpStorage = require('multer-sftp');
const cors = require('cors');
const app = express();

app.use(express.static('public'));


var storage = sftpStorage({
  sftp: {
    host: 'host',
    port: '21',
    username: 'username',
    password: 'Password'
  },
  destination: function (req, file, cb) {
    return cb(null, 'images')
  },

  filename: function (req, file, cb) { return cb(null,  Date.now() + '-' + file.originalname) }
});
const upload = multer({ storage: storage }); 


app.use(cors());

app.post('/upload', upload.single('image'), (req, res) => {
  if (req.file)
    res.json({
      imageUrl: `images/${req.file.filename}`
    });
  else 
    res.status("409").json("No Files to Upload.")
});

const PORT = 5000;

app.listen(PORT);
console.log('api runnging on port: ' + PORT);

Solution i wanted is i need to upload files to remote server using ReactJS. It would be good if some one help me to solve this.

0 Answers