From 94d3081ae946b97194cfb58a9d43421a4f5e25b0 Mon Sep 17 00:00:00 2001 From: Andi Neck Date: Mon, 4 Feb 2013 17:13:21 +0100 Subject: [PATCH] json format has changed... see: https://groups.google.com/forum/#!searchin/jquery-fileupload/empty/jquer y-fileupload/0q8PN2v0I28/pOYs76W-VsEJ and: https://github.com/blueimp/jQuery-File-Upload/wiki/Setup format: {"files": [ { "name": "picture1.jpg", "size": 902604, "url": "http:\/\/example.org\/files\/picture1.jpg", "thumbnail_url": "http:\/\/example.org\/files\/thumbnail\/picture1.jpg", "delete_url": "http:\/\/example.org\/files\/picture1.jpg", "delete_type": "DELETE" }, { "name": "picture2.jpg", "size": 841946, "url": "http:\/\/example.org\/files\/picture2.jpg", "thumbnail_url": "http:\/\/example.org\/files\/thumbnail\/picture2.jpg", "delete_url": "http:\/\/example.org\/files\/picture2.jpg", "delete_type": "DELETE" } ]} --- lib/filehandler.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/filehandler.js b/lib/filehandler.js index 6870b5d..70dec2f 100644 --- a/lib/filehandler.js +++ b/lib/filehandler.js @@ -8,14 +8,16 @@ module.exports = function (middleware, options) { var UploadHandler = require('./uploadhandler')(options); var handler = new UploadHandler(req, res, function (result, redirect) { if (redirect) { - res.redirect(redirect.replace(/%s/, encodeURIComponent(JSON.stringify(result)))); + files = {files: result}; + res.redirect(redirect.replace(/%s/, encodeURIComponent(JSON.stringify(files)))); } else { res.set({ 'Content-Type': (req.headers.accept || '').indexOf('application/json') !== -1 ? 'application/json' : 'text/plain' }); - res.json(200, result); + files = {files: result}; + res.json(200, files); } });