Strongloop file upload - conflicting containers during simultaneous uploads

17 views
Skip to first unread message

kelumch

unread,
Jul 13, 2016, 10:38:23 AM7/13/16
to LoopbackJS

I'm developing an application on strongloop which has multiple image uploads. I'm using loopback component-storage for uploading files using REST API.

The containers are dynamic (client app sends unique container ids) and I'm creating folder for the container within 'beforeRemote' using the container id. Also I have some application logic inside 'afterRemote'.

Recently I faced a strange issue that an image uploading under one container gets overridden from another image upload which happens under different container id. This was a rare issue which I came across only 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] is the 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 this sequence of steps. Images are more than 500 KB in size and image set contains 2 images.

  1. ClientA starts upload of image set -1 (upload A1)
  2. ClientB starts upload of image set -1 (upload B1)
  3. ClientA starts upload of image set -2 (upload A2)
  4. B1 upload finish - images are saved correctly
  5. A2 upload finish - one of the images missing
  6. A1 upload finish - one image is overridden by one image of B1 and it is partly saved in the disk.

Note: Client A is having poor internet connectivity and client B is having moderate level of internet connectivity.

I re-checked the container ids sent by the client and they are unique. I tried to re-create this by following the same steps as above but failed.

I'm wondering how the images got overridden by other uploads when uploading happens in parallel. I'm new to Strongloop and I really appreciate if anybody could give me a clue on the cause of this problem.

Here are my versions:

  • NodeJS : 6.0.0
  • loopback : 2.18.0
  • loopback-component-storage : 1.4.0
Reply all
Reply to author
Forward
0 new messages