0

I have a very simple node.js app that will run in my computer in conjunction with a photo booth app. Basically the photo booth software snaps a photo and then saves it in a local folder in my computer.

In my node.js app I am using chokidar as a way to watch for changes in that images folder. So whenever a new image is added, the watcher detects it and this is where I want to upload the file to a remote server.

// Initialize watcher.
var watcher = chokidar.watch('./images', {
  ignored: /[\/\\]\./,
  persistent: true
});

watcher
  .on('add', path => log(`File ${path} has been added`))
  .on('change', path => log(`File ${path} has been changed`))
  .on('unlink', path => log(`File ${path} has been removed`));

However, I am unsure on how to proceed the handling of the upload. Is there a way to get the path of this newly added image and pass it to another express middleware such as multer and then upload the image to the server? Can this be done?

lomas09
  • 1,114
  • 4
  • 12
  • 28
  • Why do you want to involve Express at all? You are watching a directory and then sending a file. You aren't listening for HTTP requests at all. (Likewise multer, it's for reading HTTP requests with files in them, but you aren't receiving one) – Quentin Jun 30 '16 at 20:29
  • How you send a file to your server depends on what type of server that is. HTTP servers, SFTP servers and SMB servers (to pick three examples) all work in different ways. In general terms the answer will be "Pick a suitable library and read its documentation" though. – Quentin Jun 30 '16 at 20:30
  • @Quentin I wasnt sure if it was possible without it. I was planning to open an index file and trigger a submit form of some kind. It sounds redundant but I couldn't think of any other way – lomas09 Jun 30 '16 at 20:31
  • Read the file from your file system. Don't read it from an HTTP request that would be a pain to create in the first place. – Quentin Jun 30 '16 at 20:32
  • @Quentin But how can it be moved to my live server? – lomas09 Jun 30 '16 at 20:34
  • See my second comment. – Quentin Jun 30 '16 at 20:36
  • @Quentin HTTP server – lomas09 Jun 30 '16 at 21:05
  • 1
    http://stackoverflow.com/questions/25344879/uploading-file-using-post-request-in-node-js – Quentin Jul 01 '16 at 06:42

0 Answers0