Comments (1)
Hi there,
i wrote this ability for my server , you can use something like that 👍
first add this class to uploadHandler.js
module.exports = class CRegExp extends RegExp { [Symbol.split](str, limit) { var result = RegExp.prototype[Symbol.split].call(this, str, limit); return result.map(x => x); } }
and next you should add blow var in UploadHandler.prototype.post = function() after finish var
contentRange = _.bind(function() { var CRange = this.req.headers['content-range']; if (typeof CRange !== 'undefined' && CRange !== null && CRange !== '') { var exp = new CRegExp(/[^0-9]+/), contentSplit = CRange.split(exp); return [contentSplit[2], contentSplit[3]]; } else { return [false, false]; } }, this);
and some changes in saving file process, this is my code
UploadHandler.prototype.post = function() { var self = this, form = new formidable.IncomingForm(), tmpFiles = [], files = [], map = {}, counter = 1, redirect, finish = _.bind(function(callb) { if (!--counter) { async.each(files, _.bind(function(fileInfo, cb) { if (!callb) { this.checkValidate(fileInfo, _.bind(function(err) { this.emit('end', fileInfo); cb(err); }, this)); } else { cb(null); } }, this), _.bind(function(err) { this.callback({ files: files }, redirect); }, this)); } }, this), contentRange = _.bind(function() { var CRange = this.req.headers['content-range']; if (typeof CRange !== 'undefined' && CRange !== null && CRange !== '') { var exp = new CRegExp(/[^0-9]+/), contentSplit = CRange.split(exp); return [contentSplit[2], contentSplit[3]]; } else { return [false, false]; } }, this); this.noCache(); form.uploadDir = options.tmpDir; form .on('fileBegin', function(name, file) { tmpFiles.push(file.path); var fileInfo = new FileInfo(file); fileInfo.safeName(); map[path.basename(file.path)] = fileInfo; files.push(fileInfo); self.emit('begin', fileInfo); }) .on('field', function(name, value) { if (name === 'redirect') { redirect = value; } if (!self.req.fields) self.req.fields = {}; self.req.fields[name] = value; }) .on('file', function(name, file) { counter++; var fileInfo = map[path.basename(file.path)]; fs.exists(file.path, function(exists) { if (exists) { fileInfo.path = path.join(options.uploadDir(), fileInfo.name); fileInfo.tmp = md5(file.path); fs.stat(fileInfo.path, function(err, stats) { if (!err && stats.isFile()) { if (contentRange()[1] && stats.size < contentRange()[1]) { var w = fs.createWriteStream(fileInfo.path, { flags: 'a' }); var r = fs.createReadStream(file.path); w.on('close', function() { finish(((parseInt(contentRange()[0]) + 1) !== parseInt(contentRange()[1])) ? true : ''); }); r.pipe(w); } } else { mkdirp(options.uploadDir(), function(err, made) { fs.rename(file.path, fileInfo.path, function(err) { if (!err) { finish((contentRange()[1]) ? true : ''); } else { var is = fs.createReadStream(file.path); var os = fs.createWriteStream(fileInfo.path); is.on('end', function(err) { if (!err) { fs.unlink(file.path); } finish((contentRange()[1]) ? true : ''); }); is.pipe(os); } }); }); } }); } else finish(); }); }) .on('aborted', function() { _.each(tmpFiles, function(file) { var fileInfo = map[path.basename(file)]; self.emit('abort', fileInfo); fs.unlink(file); }); }) .on('error', function(e) { self.emit('error', e); }) .on('progress', function(bytesReceived, bytesExpected) { if (bytesReceived > options.maxPostSize) self.req.connection.destroy(); }) .on('end', finish) .parse(self.req); };
probably you would change something to use it because i change lots of thing in my node module . Good luke
from jquery-file-upload-middleware.
Related Issues (20)
- Are there some hooks I can do my own work?
- Moving uploaded files out of the public directory HOT 3
- Orientation
- IE9 always shows a download popup for files.json HOT 3
- how to handle events depend on different router ?
- Is there a cnfiguration variable... to overwrite any existing files/images of same filename? HOT 4
- imageVersions not saving consistently HOT 1
- one file is uploaded several times
- Submit form on upload
- [Error: Request aborted] on localhost
- Thumbs not creating HOT 1
- v0.1.7 / additional input hidden fields are not being parsed
- Problem file upload with Heroku HOT 2
- Cannot res.send() in on End event
- not maintained anymore? HOT 2
- How to abort upload?
- doneAll event
- Chunks saved in separate CSV files
- Disabled local file storage
- [ERR_INVALID_CALLBACK]: Callback must be a function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-file-upload-middleware.