From 3f43f5b27829c08def8f82f74680364e5054dddd Mon Sep 17 00:00:00 2001 From: "Dhumal, Abhijeet" Date: Sat, 16 May 2015 14:56:35 +0530 Subject: [PATCH 1/2] Modifying code to accept additional form fields along with images --- index.js | 4 +++- lib/fileinfo.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d1f69d8..c135c6f 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,7 @@ function uploadService(opts) { var tmpFiles = []; var files = []; var map = {}; + var fields = {}; var redirect; this.config.host = req.headers.host; @@ -74,10 +75,11 @@ function uploadService(opts) { tmpFiles.push(file.path); // fix #41 configs.saveFile = true; - var fileInfo = new FileInfo(file, configs); + var fileInfo = new FileInfo(file, configs, fields); map[fileInfo.key] = fileInfo; files.push(fileInfo); }).on('field', function(name, value) { + fields[name] = value; if (name === 'redirect') { redirect = value; } diff --git a/lib/fileinfo.js b/lib/fileinfo.js index 3be09fd..d016be3 100644 --- a/lib/fileinfo.js +++ b/lib/fileinfo.js @@ -14,7 +14,7 @@ var getFileKey = function(filePath) { }; var udf; -function FileInfo(file, opts) { +function FileInfo(file, opts, fields) { this.name = file.name; this.size = file.size; this.type = file.type; @@ -26,6 +26,7 @@ function FileInfo(file, opts) { this.proccessed = false; this.width = udf; this.height = udf; + this.fields = fields; if (opts.saveFile) { this.safeName(); } From c3ada55565a52f5f62d83fe1ec30334a67727d8f Mon Sep 17 00:00:00 2001 From: "Dhumal, Abhijeet" Date: Sun, 17 May 2015 00:38:04 +0530 Subject: [PATCH 2/2] Correcting indentation with proper tabs/spaces --- index.js | 4 ++-- lib/fileinfo.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c135c6f..8b3da53 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ function uploadService(opts) { var tmpFiles = []; var files = []; var map = {}; - var fields = {}; + var fields = {}; var redirect; this.config.host = req.headers.host; @@ -79,7 +79,7 @@ function uploadService(opts) { map[fileInfo.key] = fileInfo; files.push(fileInfo); }).on('field', function(name, value) { - fields[name] = value; + fields[name] = value; if (name === 'redirect') { redirect = value; } diff --git a/lib/fileinfo.js b/lib/fileinfo.js index d016be3..2b76ca0 100644 --- a/lib/fileinfo.js +++ b/lib/fileinfo.js @@ -26,7 +26,7 @@ function FileInfo(file, opts, fields) { this.proccessed = false; this.width = udf; this.height = udf; - this.fields = fields; + this.fields = fields; if (opts.saveFile) { this.safeName(); }