Dropzone.js状态处于挂起状态,不上传文件

我在后端使用Multer来处理前端的file upload和Dropzone.js。 当我使用Postman来testing我的后端代码时,一切都很好,但是在使用Dropzone的时候,状态是挂起的,文件没有上传。 然后等待4分钟后,我得到超时错误。

我明确地说,使用POST而不是PUT,并立即处理file upload队列。

method: "post" autoProcessQueue: true 

我不知道是否有Dropzone.js我丢失或我的后端代码有问题的任何选项

在这里输入图像说明

这是我的节点代码来处理file upload。

 var multer = require('multer'); app.use(multer({ dest: './uploads/'})); app.post("/attachments/:code", function (req, res, next){ console.log("Posted Files: " + req.files); console.log("Posted Codes: " + req.params.code); res.status(200).send("Done"); }); app.get("/attachments/:code", function (req, res, next){ res.status(200); }); 

更新:

这是邮递员请求成功上传文件的标题:

 Accept:*/* Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Content-Length:8414633 Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryuBBzCAdVgFBBCHmB CSP:active Host:localhost:3000 Origin:chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 

这是Dropzone.js请求的标题:

 Access-Control-Request-Headers:accept, cache-control, content-type, x-requested-with Access-Control-Request-Method:POST Origin:http://localhost:9000 Referer:http://localhost:9000/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 

你可以在后处理程序中添加multer中间件:

 app.post('/upload',[ multer({ dest: './uploaded/files/', onError: function (error, next) { next(error); } } ), function (req, res) { res.status(200).send('success'); }]); 

我通过在我的节点服务器的Access-Control-Allow-Header头中启用Cache-Control来解决这个问题。

 app.use(function (req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Cache-Control, Origin, X-Requested-With, Content-Type, Accept, Authorization'); res.header('Access-Control-Allow-Methods', 'GET,PUT,PATCH,POST,DELETE'); if (req.method === 'OPTIONS') return res.end(); next(); });