Product/components used and version/fix level:
Detailed explanation of the problem:
Hi, I have deployed one image on cumulocity binary. I want to get that image based on name. What I tried, I used custom query filter and tried to filter my image with this url but it is still returning all the binaries.
<tenant_url>/inventory/binaries?withTotalPages=true&pageSize=2000&query=$filter=name eq 'Aggregation service flow.png'
How can I achieve this scenario.
Looking at the Cumulocity Open API specification, the binaries resource does not support the inventory query language.
However the meta information for the binaries are stored as inventory managed objects (marked with the
c8y_IsBinary fragment) so you can do an inventory query first to find the correct binary id, then retrieve the binary using the id.
The two-step process is detailed as follows:
Look for the id of the binary using the inventory query language
For example, filter for managed objects with the
c8y_IsBinary fragment, and the name matching
Aggregation service flow.png.
GET /inventory/managedObjects?query=$filter=has(c8y_IsBinary) and name eq 'Aggregation service flow.png'
The REST API above will return all the matching binary meta information managed objects, so select the appropriate
Using the binary id found in the previous step, get the binary file using the binary API:
If you’re a go-c8y-cli user, you could do the same lookup using the following chained commands (which does exactly the same as above, but using shell pipeline):
c8y inventory find --query "has(c8y_IsBinary) and name eq 'Aggregation service flow.png'" | c8y binaries get
Thank you for the response. It is working as expected, but I have one doubt. How Can I fetch this image or the doc whatever I have stored in binary in my code through rest API. I will get the response in postman but how can i fetch it in my code.
Lets say If I have stored 1 image and 1 doc, and I get the ids and i am trying to fetch it from binary, what object or what type will be returned by cumulocity in this case?
it will be returned as the content-type which has been provided while posting the binaries.
The response will have the content-type
text/csv which needs to be handled in your code accordingly.