0

i am using loop back storage component for file upload. request contains both file and user data. After file upload, i need user data to save file info. I am trying to access user data using beforeRemote method and afterRemote method as below:

Storages.beforeRemote('upload', function (context, unused, next) {
     console.log(context.req.body)

    next();
});

Storages.afterRemote('upload', function (context, unused, next) {
     console.log(context.req.body)
    next();
});

but it did not work. is there any way to access request params in remote methods?

srinivas
  • 109
  • 1
  • 3
  • 14
  • For more info on accessing and modifying request param for file upload check it out:- http://stackoverflow.com/questions/31048618/modify-image-obtained-from-loopback-component-storage/31059880#31059880 – Robins Gupta Nov 07 '16 at 21:50

2 Answers2

0

I can access the request data in context.a result which looks like

{
    result: {
        files: {
            file: [object]
        },
        {
            fields: {
                name: [object]
            }
        }
    }
}

files are your uploaded file and fields is your form fields.

lazzy_ms
  • 1,169
  • 2
  • 18
  • 40
srinivas
  • 109
  • 1
  • 3
  • 14
-1

You can get body data inside context.args.data

Try:

Storages.beforeRemote('upload', function (context, unused, next) {
    console.log(context.args.data)
    next();
});
Tatsuyuki Ishi
  • 3,883
  • 3
  • 29
  • 41