Tag: dropzone.js

如何处理expressjs中间件请求。 POST请求由dropzone保持挂起

我正在使用dropzone上传文件。 在服务器端我使用节点和expressjs。 我也使用MULTER作为文件处理中间件。 dropzone调用一个端点来保存服务器上的文件。 在服务器端,我创build了一个端点来处理文件: exports.saveFile = function (req, res) { console.log(req.files); return res.status(200); //I have not added any file save logic here }; 这是我如何configuration的Muller var app = express(); var server = require('http').createServer(app); app.use(multer({ dest: './uploads/'})); 看起来像multer自动将文件保存到uploads文件夹。 问题 :即使文件保存在服务器上,请求在客户端仍然处于挂起状态。 我怎样才能返回从服务器到客户端的成功响应? 我是否需要在已创build的端点上添加一些代码,或者是否需要在multer提供的onFileUploadComplete()下添加所需的逻辑?

图片上传 – 如何获得适合服务器端处理的图片数据格式

我使用sharp来处理服务器端的图像, 并对dropzone进行反应以获取图像文件。 当我从dropzone发布文件到服务器,我得到的blob从request.body看起来像这样: { preview: 'blob:http%3A//127.0.0.1%3A3000/1451580a-b24f-478f-a9f7-338c0d790829' } (可选)在将数据发送到服务器之前,我可以使用FileReader(或其他)来对图像文件进行操作,而不是将其转换为Blob。 夏普需要: 包含JPEG,PNG,WebP,GIF,SVG,TIFF的缓冲区 原始像素图像数据 包含图像文件path的string,支持大多数主要格式。 我如何使用我必须提供的支持格式?

dropzone nodejsfile upload

我打算使用DropZone将file upload到我的nodejs服务器。 但是,我不知道如何得到一个文件句柄,当这个post命中我的nodejs服务器。 下面是我如何在我的html中实例化DropZone: <form action="/file-upload" class="dropzone" id="logoDropZone"> <input type="hidden" name="userName" value="user"/> </form> 然后,在我的nodejs服务器,我有以下代码: app.post('/file-upload', function (request, response) { console.log("Route: '/file-upload' "); console.log("File upload request from user: " + request.body.userName); // Get a file handle, read the file and then write it out to the file system. … }); 我可以看到这个代码正在执行。 我也可以通过请求对象访问input字段中的值(参见隐藏的input)。 但是,如何访问文件本身,以便将其写入服务器文件系统?

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 […]

使用Dropzone上传多个文件与节点multer时,LIMIT_UNEXPECTED_FILE问题

在前端使用Dropzone在一个请求中将多个file upload到服务器,并使用Multer中间件来处理多部分/表单数据。 在Dropzoneconfiguration文件中设置uploadMultiple uploadMultiple: true ,会在名称后加上[]。 例如,名称将是文件[0],文件1等 服务器端代码: var uploader = multer({dest: dest}); router.post(url, uploader.array('files', 30), function(req, res) { … }); 但是,似乎multer()。array(fieldname)只允许fieldname匹配表单数据中的名称。 否则,它会抛出LIMIT_UNEXPECTED_FILE错误。 任何build议,通过将名称始终作为“字段”而不是附加[]或使得Muller处理不同的名称来解决这个问题?

NodeJS dropzone软件包的安装

我想在节点项目上部署一个dropzone组件。 我input了: npm install dropzone 这给了我这些文件: node_modules/dropzone/dist/dropzone.js node_modules/dropzone/dist/dropzone.css 但我不明白为什么这些文件不会自动复制在公共/文件夹。 我不得不手动将这些文件复制到我的公共/ css和public / js文件夹。 它工作正常,但我想知道如果我的副本脏或不。 有没有最简洁的方法来安装dropzone组件?

使用dropzone上传照片时显示错误

您好我有上传图像在jQuery中的问题。 当我uplaod图像,显示我的错误。 我如何解决这个问题? 我不能使用表单来dropzone,因为它是另一种forms。 错误: POST http:// localhost:3000 / upload 400(Bad Request) Object {error:Object} 代码的HTML <div class="dropzone" action="/upload" encType="multipart/form-data" method='post' id="id_dropzone" > <div class="dz-message"> ِDrop file here to upload </div> </div> 代码JQUERY $(document).ready(function(){ Dropzone.autoDiscover = false; $("#id_dropzone").dropzone({addRemoveLinks: true, autoQueue: true,paramName: "file", maxFilesize: 2, maxFiles: 1, success: function (file, response) { var imgName = response; file.previewElement.classList.add("dz-success"); […]

使用发送事件以编程方式创buildDropzone发送附加数据

我有以下(简化例如)angular度指令创build一个dropzone directives.directive('dropzone', ['dropZoneFactory', function(dropZoneFactory){ 'use strict'; return { restrict: 'C', link : function(scope, element, attrs){ new Dropzone('#'+attrs.id, {url: attrs.url}); var myDropZone = Dropzone.forElement('#'+attrs.id); myDropZone.on('sending', function(file, xhr, formData){ //this gets triggered console.log('sending'); formData.userName='bob'; }); } } }]); 正如你可以看到sending事件处理程序,我试图发送用户名(“bob”)以及上传的文件。 但是,我似乎无法在我的路由中间件中检索它,因为req.params作为一个空数组返回(我也尝试了req.body )。 我的节点路由 { path: '/uploads', httpMethod: 'POST', middleware: [express.bodyParser({ keepExtensions: true, uploadDir: 'uploads'}),function(request,response){ // comes back as […]

hapi.js Cors Pre-flight不返回Access-Control-Allow-Origin标题

我有一个使用(Dropzone js)的ajaxfile upload。 将文件发送到我的hapi服务器。 我意识到浏览器发送了一个PREFLIGHT OPTIONS METHOD。 但我的hapi服务器似乎不发送正确的响应头,所以我得到铬上的错误。 这是我在铬上得到的错误 XMLHttpRequest cannot load http://localhost:3000/uploadbookimg. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. 这是hapi js路由处理程序 server.route({ path: '/uploadbookimg', method: 'POST', config: { cors : true, payload: { output: 'stream', parse: […]

使用NodeJS进行多部分file upload

我有麻烦获取file upload与NodeJS工作。 我正在使用Dropzone.JS来创build一个发送POST请求到/ file-upload的表单: <form action="/file-upload" class="dropzone dragndrop" id="my-awesome-dropzone"></form> 然后我在app.js中有一个路由: app.post('/file-upload', routes.upload); 然后我的经理: exports.upload = function(req, res){ console.log(req.files); res.send("OK"); } 但是,这里的上传function从来没有被调用过。 服务器首先崩溃,出现这个错误: events.js:69 throw arguments[1]; // Unhandled 'error' event ^ Error: Invalid data at WriteStream._write (fs.js:1616:31) at onwrite (_stream_writable.js:265:14) at WritableState.onwrite (_stream_writable.js:94:5) at fs.js:1628:5 at Object.wrapper [as oncomplete] (fs.js:475:5) at process._makeCallback (node.js:321:24) 所以我不确定我该怎么做,因为这似乎不是我的错。 我跟着其他教程,看到没有错。 另外,当我使用chrome […]