0

I have simple grunt-contrib-connect server. It exists jut for local use, just for local access.

I'd like to have ability to choose files from my file system and put them in a directory in my grunt project.

Here's my HTML:

<form method="post" name="upload" action="uploaded" enctype="multipart/form-data">
  <input type="file" name="files" multiple accept=".jpg,.png">
  <input type="submit">
</form>

Here I run connect:

grunt.config('connect.ui', {
 options: {
  port: 9000,
  protocol: 'http',
  hostname: 'localhost',
  keepalive: true,
  middleware: [
   function theMiddleware(req, res) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    processRequest(req, res);
   }
  ]
 }
});

But I really don't have any ideas how to put selected files in directory of grunt project.

I'll be glead to hear any ideas or solutions.

Thanks in advance.

1 Answers1

3

it should probably be fairly easy using the multer-middleware:

var multer = require('multer');
grunt.config('connect.ui', {
    options: {
        port: 9000,
        protocol: 'http',
        hostname: 'localhost',
        keepalive: true,
        middleware: [multer({ dest: './your-upload-folder/'})]
    }
});
hereandnow78
  • 14,094
  • 8
  • 42
  • 48