dropzonejs配置对节点js无效

时间:2018-07-24 11:17:55

标签: javascript node.js dropzone.js

我正在尝试使用node.js创建拖放文件上传器,当我将代码作为单独的html文件运行并调用和外部cofig.js文件时,它运行良好。

但是,当我尝试使用rew.write打印html时,这些配置不适用于dropzone上传器。我上传的文件,尽管上传成功。

这是我的代码:

var http = require('http');
var formidable = require('formidable');
var request = require('request');
var fs = require('fs');


http.createServer(function (req, res) {
  if (req.url == '/fileupload') {
    var form = new formidable.IncomingForm();
    form.keepExtensions = true;
    form.uploadDir = "./";

    form.hash = 'md5';

    form.parse(req, function (err, fields, files) {
      res.write('File uploaded');

      res.end();
    });
  } else {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write ('<html><head><title>Dropzone </title><link href="http://cdnjs.cloudflare.com/ajax/libs/dropzone/3.8.4/css/basic.css" rel="stylesheet"></head><body><form method="post" action="/fileupload"   class="dropzone" id="uploader" enctype="multipart/form-data"><button>Save</button></form><script src="http://cdnjs.cloudflare.com/ajax/libs/dropzone/5.2.0/dropzone.js"></script><script src = "config.js"></script></body></html>');

    return res.end();
  }


}).listen(8080);

预先感谢

0 个答案:

没有答案