0 Favourites

[solved]How do I display an image getting from HTTP GET

  • I want to display an image using a sprite object, and the source of the image is a dynamic url which is a HTTP Get request. The response of the GET is binary datas. Can I use AJAX? or use sprite's Load image from URL to get the image? and how can I handle the response?

    p.s. The GET URL is cross domain.

    Any one can help me? thanks a lot.

    [Solution]

    1. Via php script get the remote image binary datas, and save it to local server as jpg or png etc.

    2. Use sprite's Load image from URL to display that image.

  • You cannot use the AJAX object, only Sprites 'Load image from URL'. You don't need to do anything other than give it the URL, but you must have permission to load images from the server (look up the Access-Control-Allow-Origin HTTP header).

  • Thanks Ashley, I will try it and report the results later.

  • You cannot use the AJAX object, only Sprites 'Load image from URL'. You don't need to do anything other than give it the URL, but you must have permission to load images from the server (look up the Access-Control-Allow-Origin HTTP header).

    Ashley, I‘ve tried 'Load image from URL', but it didn't work.

    I should say that the URL is a servlet, just like this: 'http://aaa.bbb.com/Querylet?Id=anystring', Id is a in-parameter

    and the response will like these:

    Content-Type: image/jpeg;\r

    Content-Length: xx\r

    \r

    so...'Load image from URL' didn's get anything.

  • KennyOops - yes, you will need to configure Access-Control-Allow-Origin in the server's HTTP response for it to work.

  • Ashley

    woo... I can't configure the server's HTTP response, it's a third-party server....now, it's a serious problem.

    what else can I do?

  • Nothing. This is how Internet security works: you cannot load resources from third party servers unless they explicitly let you.

  • Ashley

    woo... I can't configure the server's HTTP response, it's a third-party server....now, it's a serious problem.

    what else can I do?

    It is also illegal to load other websites images/media without consent, AND Hotlinking is a crime.

  • Thank you Ashley DUTOIT.

    The third-party server is a legal charging server, and the image I should get is a verify-code image.

    Can I use AJAX plugin requests my php interface to get the image from the third-party? The php interface is deployed on the same server with my game, via php I get and then process the image binary data, echo the response in the end.

    If so, anything can process the Ajax.LastData?

  • You don't load an image from an Ajax request, you just get the URL. You can use standard URL encoding to pass any parameters you need to to the server.

    I doubt your third-party is going to let you run XSS anytime ever so as a workaround you can have them fetch the image from your server via a PHP script that gets it from the other server. It may lag a bit more than usual but it should work.

  • You don't load an image from an Ajax request, you just get the URL. You can use standard URL encoding to pass any parameters you need to to the server.

    I doubt your third-party is going to let you run XSS anytime ever so as a workaround you can have them fetch the image from your server via a PHP script that gets it from the other server. It may lag a bit more than usual but it should work.

    nusbaumc, you remind me of fetching it from remote server in the first, and then there is no Cross-Domain problem. Thank you.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Ashley do you know if Load image from URL work on iOS when you export with Ejecta.?

  • Hi, KennyOops

    Ive got a similar issue, but ive got the HTTP response set to allow CORS.

    How did you make the "GET URL" cross domain.?

    If someone could help, I'd be very grateful.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)