简体   繁体   English

node.js和快速文件上传器

[英]node.js and express file uploader

So I am following this tutorial: http://thejackalofjavascript.com/uploading-files-made-fun/ 因此,我正在关注本教程: http : //thejackalofjavascript.com/uploading-files-made-fun/

I have followed the steps all the way up to where they create the routes and haven't actually created any views. 我一直遵循这些步骤,直到他们创建路线为止,实际上并没有创建任何视图。 It says 它说

Thats it we are all done with our server. 就这样,我们的服务器都完成了。 Restart your server and navigate to http://localhost:3000/upload . 重新启动服务器并导航到http://localhost:3000/upload You should see a JSON response with the empty array of files. 您应该看到一个带有空文件数组的JSON响应。

However when I try to run app.js it sits for a few seconds and then just goes back to the command prompt. 但是,当我尝试运行app.js时,它会停留几秒钟,然后返回到命令提示符。 No errors are given and I am clueless as to how to fix this. 没有给出任何错误,我对如何解决这个问题一无所知。

Here is my code in routes/uploadManager.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;
}

I apologize. 我道歉。 I was trying to run node app.js when I was supposed to be running node bin/www since this is an express.js app. 我应该在运行node bin/www时尝试运行node app.js ,因为这是一个express.js应用程序。

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

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