I need to find a way to change the content type of a response I'm sending from a custom remote method. It seems that by default it's application/json.
I have a remote method that returns images, so it i need somehow to change the Content-Type.
I need to find a way to change the content type of a response I'm sending from a custom remote method. It seems that by default it's application/json.
I have a remote method that returns images, so it i need somehow to change the Content-Type.
Register remote hook and then set header on express-like res
from context object. In the end call next function (if it's defined) to continue execution.
Model.afterRemote('fetch', function(ctx, instance, next) {
ctx.res.header('Content-Type', 'image/png');
next && next();
});
You could add the response
object of express to your method signature
Model.remoteMethod(
'yourMethod',
{
accepts: [
{ arg: 'id', type: 'number', required: true },
{arg: 'res', type: 'object', 'http': {source: 'res'}}
],
http: {path: '/method/:id', verb: 'get'}
}
);
and then use this object to set the content-type
Model. yourMethod = function(id, res, cb) {
res.type("image/png");
cb();
}