API Structure : Images
Overview
Fetching an organization unit image from DHIS2 can be challenging due to Cross-Origin Resource Sharing (CORS) issues and the need to manage authentication securely. To simplify this process, we've introduced a dedicated endpoint. This endpoint allows for easy integration of organization unit images into web applications by directly using the image URL in the src
attribute of an img
tag.
Endpoint Details
URL: api/v2/proxy/images/{resourceId}
Method: GET
Authorization: Open (No authentication required for accessing images)
Usage Example
You can directly embed the image in your HTML using the img
tag. The onerror
attribute is used to handle cases where the image is not available or cannot be loaded, displaying an alternative image instead.
<img src="${baseURL}/proxy/images/${facility.image}"
onerror="this.onerror=null; this.src='${noPicture}';"
alt="Facility Image"/>
Parameters:
${baseURL}
: The base URL of your API.${facility.image}
: The unique identifier for the facility's image.${noPicture}
: URL of a fallback image to display if the main image fails to load.