繁体   English   中英

node.js和快速文件上传器

[英]node.js and express file uploader

因此,我正在关注本教程: 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 bin/www时尝试运行node app.js ,因为这是一个express.js应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM