node.js - Strongloop file upload - conflicting containers during simultaneous uploads -
i'm developing application on strongloop has multiple image uploads. i'm using loopback component-storage uploading files using rest api.
the containers dynamic (client app sends unique container ids) , i'm creating folder container within 'beforeremote' using container id. have application logic inside 'afterremote'.
recently faced strange issue image uploading under 1 container gets overridden image upload happens under different container id. rare issue came across twice.
beforeremote method:
mymodel.beforeremote('upload', function (ctx, res, callback) { var arrstr = ctx.req.url.split(/[//]/); var mkdirp = require('mkdirp'); var path = '../storage/images/' + arrstr[1]; //arrstr[1] container folder mkdirp(path, function (err) { console.log(err); }); callback(); });
afterremote method:
mymodel.afterremote('upload', function (ctx, res, callback) { var mainlogics = function(){ var file = res.result.files.file[0]; if (file != undefined) { if (file != null) { var mydata = res.result.fields.data[0]; if (mydata != undefined) { //my application logic callback(); } else callback(); } else callback(); } } mainlogics(); });
the conflict of images occurred during sequence of steps. images more 500 kb in size , image set contains 2 images.
- clienta starts upload of image set -1 (upload a1)
- clientb starts upload of image set -1 (upload b1)
- clienta starts upload of image set -2 (upload a2)
- b1 upload finish - images saved correctly
- a2 upload finish - 1 of images missing
- a1 upload finish - one image overridden 1 image of b1 , partly saved in disk.
note: client having poor internet connectivity , client b having moderate level of internet connectivity.
i re-checked ids sent client , unique. tried re-create following same steps above failed.
i'm wondering how images got overridden other uploads when uploading happens in parallel. i'm new strongloop , appreciate if give me clue on cause of problem.
here versions:
- nodejs : 6.0.0
- loopback : 2.18.0
- loopback-component-storage : 1.4.0
Comments
Post a Comment