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:
我正在使用环回存储组件进行文件上传。请求包含文件和用户数据。文件上传后,我需要用户数据来保存文件信息。我正在尝试使用beforeRemote方法和afterRemote方法访问用户数据,如下所示:
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?
但它不起作用。有没有办法在远程方法中访问请求参数?
2 个解决方案
#1
0
I can access the request data in context.result which looks like { result: { files: { file: [object] }, { fields: { name: [object] } } } }
我可以访问context.result中的请求数据,它看起来像{result:{files:{file:[object]},{fields:{name:[object]}}}}
files is your uploaded file and fields is your form fields.
文件是您上传的文件,字段是您的表单字段。
#2
0
You can get body data inside context.args.data
您可以在context.args.data中获取正文数据
Try:
尝试:
Storages.beforeRemote('upload', function (context, unused, next) {
console.log(context.args.data)
next();
});
#1
0
I can access the request data in context.result which looks like { result: { files: { file: [object] }, { fields: { name: [object] } } } }
我可以访问context.result中的请求数据,它看起来像{result:{files:{file:[object]},{fields:{name:[object]}}}}
files is your uploaded file and fields is your form fields.
文件是您上传的文件,字段是您的表单字段。
#2
0
You can get body data inside context.args.data
您可以在context.args.data中获取正文数据
Try:
尝试:
Storages.beforeRemote('upload', function (context, unused, next) {
console.log(context.args.data)
next();
});