Layer 7 API Management

Expand all | Collapse all

The best practice for get an image with an api

Jump to Best Answer
  • 1.  The best practice for get an image with an api

    Posted 8 days ago
    Hi Community,

    I would like to know wich is the best way for get an image.jpg with an api and if i need an special configuiration for this mime type?

    Regards,

    Julio Ramos.

    ------------------------------
    [Julio C. Ramos]
    [DevOps]
    [IT Business Solutions DEF]
    [City]
    ------------------------------


  • 2.  RE: The best practice for get an image with an api

     
    Posted 6 days ago

    Julio,
    Sorry I dont quite understand the question can you give more details and use case?

    Are you getting a response from an http route in the gateway, which includes an image (jpg)? And want this to be passed to the browser? Are you trying to change the mime? Or just pass through? Could you add some details?
    Thanks..




  • 3.  RE: The best practice for get an image with an api

    Posted 5 days ago
    From my perspective, how would a service return an image (jpg, png, etc.)?  The content-type can be set to an image type in the template response but there is no way to return the image itself.  Base64 encoding the image and including it in the body of the template response does not "work" from a browser.


  • 4.  RE: The best practice for get an image with an api

    Posted 5 days ago
    Hi Jackie,

    Try this to return an image. The template content-type has to he set to HTML.


    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
    <wsp:All wsp:Usage="Required">
    <L7p:HardcodedResponse>
    <L7p:Base64ResponseBody stringValue="PGltZyBzcmM9ImRhdGE6aW1hZ2UvcG5nO2Jhc2U2NCxpVkJPUncwS0dnb0FBQUFOU1VoRVVnQUFBUUFBQUFFQUNBTUFBQUJyckZoVUFBQUFZMUJNVkVYLy8vLzAvdjFQVlZkQlIwajgrdmYxOWZVUkR3MysvLzcrL1A3Ny9QejNCQVo1ZTN2cjdlei84T3ZsQ1JLZ29xS1BrSTh1TENyYzNkNWxaMmpPejgvTkVoeSt3TUN4c2JIL3E2Ny8yOXIveGNQaFAwUzBKUzM3YjNUK2tKTFdVbGk5b2FNaUdjNllBQUFPamtsRVFWUjQydTFiNjNyaU9CYjBSWXFrbG95TkxHd2d0M24vcDl5cUl4dVN6UFIr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1NmTE1TMy9yNFM3NzliMW9mblhFQ0F6RmJJVmxtdDZ1Nk82djZXbnY2VXJYMy9aL3NzTzRrKzdpUC9MNSs2cjFMOExBM1YvNHBZT3RnVnE5KzM1K2JjUmw4eU8zUHloOFkxQ29WQW9GQXFGUXFGUUtCUUtoVUtoVUNnVUNvVkNvVkFvRkFxRlFxRlFLQlFLaFVLaFVDZ1VDb1ZDb1ZBb0ZBcUZRcUZRS0JRS2hVS2hVQ2dVQ29WQ29WQW9GQXFGUXFGUUtCUUtoVUtoVUNnVUNvWGkvNHovQUYzcytBR0J1L2N3QUFBQUFFbEZUa1N1UW1DQyIgLz4="/>
    <L7p:ResponseContentType stringValue="text/html; charset=UTF-8"/>
    </L7p:HardcodedResponse>
    </wsp:All>
    </wsp:Policy>


  • 5.  RE: The best practice for get an image with an api

    Posted 5 days ago
    Thanks Joe. That does work. However, it's really the worst of both worlds. It pulls back the Base64 string and that big string gets loaded with the HTML page. In that case you might as well just embed the Base64 string in the page itself and save the call to the route assertion. If the image is not static then I suppose this is the only way to go though.


  • 6.  RE: The best practice for get an image with an api
    Best Answer

    Posted 5 days ago
    Hi Charles, thanks for your replies folks,

    Well, the scenario is request an image from an internal image repository services after getting the id for the image an return in the api response.

    I have tested using a reverse proxy to getting the image url and i can see the response with a content type "image/jpg" using the ${response} variable, so i´m using a http route to get the image an return the response directly.

    This is working fine for me.

    Regards.


    ------------------------------
    [Julio C. Ramos]
    [DevOps]
    [IT Business Solutions DEF]
    [City]
    ------------------------------



  • 7.  RE: The best practice for get an image with an api

    Posted 5 days ago
    Hi Charles, thanks for your replies folks,

    Well, the scenario is request an image from an internal services after getting the id for the image an return in the api response.

    I have tested using a reverse proxy to getting the image url and i can see the response with a content type "image/jpg" using the ${response} variable, so i´m using a http route to get the image an return the response directly.

    Regards,

    ------------------------------
    [Julio C. Ramos]
    [DevOps]
    [IT Business Solutions DEF]
    [City]
    ------------------------------