0

我有简单的 grunt-contrib-connect 服务器。它的存在只是为了本地使用,只是为了本地访问。

我希望能够从我的文件系统中选择文件并将它们放在我的 grunt 项目的目录中。

这是我的 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>

在这里我运行连接:

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);
			}
		]
	}
});

但我真的不知道如何将选定的文件放在 grunt 项目的目录中。

我会很高兴听到任何想法或解决方案。

提前致谢。

4

1 回答 1

3

使用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/'})]
    }
});
于 2015-04-29T11:18:13.320 回答