所以我有一堆文件,我希望用户能够通过提交表单下载(我想发送一个获取请求)。有人能告诉我如何更改我的观点,路线和app.js文件才能做到这一点?是否应该在index.js文件中处理路由(用户可以在哪里下载文件)?或者我应该使用app.js文件创建一个全新的路线?
编辑:我使用multer上传文件。
此时我的代码有点分散:
在app.js中我们有这个:app.get('/download', function(req, res, next){
var file = req.params.file
, path = __dirname + '/uploads/' + file;
res.download("upload/a.tiff");
});
在index.jade中我们有这个:
h2 Download
form(action="/download", method="get")
input(type="submit", name="downLoad")
index.js文件中没有任何相关内容,但有一次我在app.js中有了我在index.js文件中列出的函数。这似乎不起作用。
现在我刚刚尝试下载一个a.tiff文件。
这是错误:
404
Error: Not Found
at app.use.res.render.message (/Users/brennan/personal/dev/shareBetweenComputers/app.js:39:13)
at Layer.handle [as handle_request] (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:302:13)
at /Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:270:7
at Function.proto.process_params (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:321:12)
at next (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:261:10)
at /Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:603:15
at next (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:246:14)
at Function.proto.handle (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:166:3)
at router (/Users/brennan/personal/dev/shareBetweenComputers/node_modules/express/lib/router/index.js:35:12)
我是否需要写下载路线?
Remote Address:127.0.0.1:3000
Request URL:http://localhost:3000/download?downLoad=Submit
Request Method:GET
Status Code:404 Not Found