node.js和express文件上传器

node.js and express file uploader

本文关键字:文件 express js node      更新时间:2023-09-26

所以我遵循本教程:http://thejackalofjavascript.com/uploading-files-made-fun/

我一直遵循这些步骤,直到他们创建路线的地方,实际上还没有创建任何视图。上面写着

就这样,我们的服务器都用完了。重新启动服务器,然后导航到http://localhost:3000/upload。您应该看到一个JSON使用空的文件数组进行响应。

然而,当我尝试运行app.js时,它会停留几秒钟,然后返回命令提示符。没有给出任何错误,我也不知道如何解决这个问题。

这是我在routes/uploadManager.js 中的代码

var options = {
tmpDir:  __dirname + '/../public/uploaded/tmp',
uploadDir: __dirname + '/../public/uploaded/files',
uploadUrl:  '/uploaded/files/',
maxPostSize: 11000000000, // 11 GB
minFileSize:  1,
maxFileSize:  10000000000, // 10 GB
acceptFileTypes:  /.+/i,
// Files not matched by this regular expression force a download dialog,
// to prevent executing any scripts in the context of the service domain:
inlineFileTypes:  /'.(gif|jpe?g|png)/i,
imageTypes:  /'.(gif|jpe?g|png)/i,
imageVersions: {
    width:  80,
    height: 80
},
accessControl: {
    allowOrigin: '*',
    allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE',
    allowHeaders: 'Content-Type, Content-Range, Content-Disposition'
},
storage : {
    type : 'local'
}
};
var uploader = require('blueimp-file-upload-expressjs')(options);
module.exports = function (router) {
router.get('/upload', function (req, res) {
    uploader.get(req, res, function (obj) {
        res.send(JSON.stringify(obj));
    });
});
router.post('/upload', function (req, res) {
    uploader.post(req, res, function (obj) {
        res.send(JSON.stringify(obj));
    });
});
router.delete('/uploaded/files/:name', function (req, res) {
    uploader.delete(req, res, function (obj) {
        res.send(JSON.stringify(obj));
    });
});
return router;
}

我道歉。我正试图运行node app.js,而我本应该运行node bin/www,因为这是一个express.js应用程序。