cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP CAPIRE 7.0 and external REST Services + Binary Data

matteoprinetti
Participant
0 Kudos
558

Im implementing a CAP Server with fetches Images from a external Service.

The cds is

entity ImageResource {
key id : String;
content : LargeBinary @Core.MediaType: 'image/jpeg';
}

I connect to the service using cds.connect.to

 const extApi = await cds.connect.to({
kind: "rest",
impl: "srv/external/myApi.js",
credentials: {
url: process.env.SERVER_URL
}
});
And in my Rest implementation I fetch the image:
req.query = `GET /api/planogram/resource/image/` + req.query.SELECT.from.ref[0].where[2].val;
The problem: the remote service implementation from Capire use Axios to get the data: The only way I found to set the ResponsType to arrayBuffer is:
req._binary = true;
I think this is a bug somewhere in cds runtime lib / or the documentation how to set this flag beside using the _binary is missing.
I For the records reading the image and giving it back to odata is straightforward:

const response = await next(req);
const readable = new Readable();
readable.push(response);
readable.push(null);
return [{
value: readable,
$mediaContentType: 'image/jpeg'
}]

Accepted Solutions (0)

Answers (0)