javascript - Handling uploads with skipper in sails.js (on progress) -



javascript - Handling uploads with skipper in sails.js (on progress) -

i using skipper upload multiple files @ 1 time local folder. ran few problems.

upload: function (req, res) { if (_.isempty(req.session.user)){ homecoming res.json({ //---> 1 success: 0 }); }else{ res.settimeout(0); var maxbytes = 10*1000*1000; //---> 2 if (req._fileparser.form.bytesexpected > maxbytes){ homecoming res.json({ success: 0, error: 'file size limit exceeded.' }); }else{ req.file('file[]').on('progress', function(event){ homecoming event; //---> 3 }).upload({ maxbytes: maxbytes }, function whendone(err, uploadedfiles) { //---> 4 homecoming res.json({ success: 1, }); }); } } },

first error //---> 1 if user not logged in want end upload process , homecoming success = 0. not working. @ client side request kept hanging without response.

second error //---> 2 ran error before described here https://github.com/balderdashy/skipper/issues/36 , quick prepare used used in comments @ github. 1 time again in problem 1, ran issue. if file size exceeds of maxbytes, want end upload process , homecoming success = 0 user. isn't going client side.

third error //---> 3 want utilize on progress create progress bar. ran few issues. first of all, using on progress slows scheme downwards much. leads error in 4th step.

fourth error //---> 4 if remove on('progress') step 3, works expected. on completing upload, returns success = 1 client. however, when on('progress') nowadays return res... in step //---> 4 doesn't work , 1 time 1 time again client request kept hanging without response.

few questions: why doesn't next code work in //---> 1 while works in //---> 4 if on('progress') not present

return res.json({ success: 0 });

why on progress slow downwards upload process much?

btw on client side utilize form.js plugin. , hence request looks this:

$('#upload').ajaxform({ uploadprogress: function(event, position, total, percentcomplete){ console.log(percentcomplete); }, success: function(data) { console.log(data); } });

it took me time solve this, , time did, had forgotten question here @ stackoverflow. these of steps took create work.

upload: function (req, res) { if (_.isempty(req.session.user)){ homecoming res.json({ // or destroy connection shown below success: 0 }); }else{ res.settimeout(0); var maxbytes = 10*1000*1000; if (req._fileparser.form.bytesexpected && req._fileparser.form.bytesexpected > maxbytes) { // file size exceeded //-> check filesize on client-size before uploading because not send error study client req.connection.destroy(); } req.file('file[]').on('progress', function(event){ // returning here unnecessary // illustration jquery form plugin's client-side `uploadprogress:` still grab progress }).upload({ maxbytes: maxbytes }, function whendone(err, uploadedfiles) { var tempfilenames = _.pluck(uploadedfiles, 'fd'); if (_.isempty(tempfilenames)) { homecoming res.json({ success: 0, error: '0 files selected.' }); }else{ // process upload homecoming res.json({ success: 1, }); } }); } },

this still not best solution. find of hacky. if has improve solution, please share.

javascript node.js sails.js skipper

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -