[Html2PdfConverter] GenerateImage not working with certain URLs

[Html2PdfConverter] GenerateImage not working with certain URLs

  
Forge Component
(43)
Published on 8 Nov by Guilherme Pereira
43 votes
Published on 8 Nov by Guilherme Pereira

I'm trying to use GenerateImage from this component on an OutSystems 10 module and I'm getting no binary data when I supply a URL like: http://kids.nationalgeographic.com/content/dam/kids/photos/animals/Amphibians/Q-Z/red-eyed-tree-frog-on-leaves.ngsversion.1468593394199.jpg

If I send something like the following I DO get an image though:

http://google.com

http://bing.com

etc.


Is there something about URLs that end with file extensions that causes this behavior? So far that's the only consistent thing I can find with the URLs I have tried that don't work.

Any help on this would be greatly appreciated.

Solution

not sure, but is it a page that you get back or an actual image?

it should be a proper html to be converted to an image imho.


Solution

J. wrote:

not sure, but is it a page that you get back or an actual image?

it should be a proper html to be converted to an image imho.


After leaving work and having a break to think about it I realized the same thing. The reason why I didn't think that was the problem at first was because navigating to the image on Chrome, Edge or some other browser would result in a HTML page to view.

I realize now that this is probably because the browser is building a page to surround the image in (so it's able to be viewed directly on the browser). I'll try putting the image I need in a simple webscreen and pass that URL to GenerateImage and see if that fixes my problem (I highly suspect it will).


If you already have an URL for the image file, there's no point in using GenerateImage. GenerateImage is useful when you want to transform HTML into an image, not to transform an image into another image (see how redundant it is?).

You probably want to use the GetRequest_Submit action from HTTPRequestHandler extension, or some equivalent from ardoHTTP.

Leonardo Fernandes wrote:

If you already have an URL for the image file, there's no point in using GenerateImage. GenerateImage is useful when you want to transform HTML into an image, not to transform an image into another image (see how redundant it is?).

You probably want to use the GetRequest_Submit action from HTTPRequestHandler extension, or some equivalent from ardoHTTP.

It does seem rather silly when you put it that way, but I specifically need the image binary data back for the image in question and the image is hosted on another service that I don't have direct access to (only the URL for an image I request is sent back). I'm totally new to OutSystems so I don't know a better way to get what I'm looking for. Just glancing at ardoHTTP nothing jumps out at me. Is there a way to use that to get the binary data for an image hosted somewhere like: http://kids.nationalgeographic.com/content/dam/kids/photos/animals/Amphibians/Q-Z/red-eyed-tree-frog-on-leaves.ngsversion.1468593394199.jpg ?


Sure Trevor. You need to make a GET request, and retrieve the binary that comes in the response.

I had a look into ardoHTTP and it seems to me that it only supports text responses (such as HTML and JSON). So you would have to use the GetRequest_Submit from HTTPRequestHandler.

The HTTPRequestHandler is an extension that comes with the platform, so you don't need to install anything from forge, just need to add references to it. The GetRequest_Submit has a BinaryContent output, which is what you need.


I think you are going to run into a problem with those URLs. When I click them, I'm redirected to the nat. geo. home page. The server is probably defending against external linking. But, for now, just try to use the API to retrieve the contents of the URL, and if you run into problems get back to me.

Leonardo Fernandes wrote:

Sure Trevor. You need to make a GET request, and retrieve the binary that comes in the response.

I had a look into ardoHTTP and it seems to me that it only supports text responses (such as HTML and JSON). So you would have to use the GetRequest_Submit from HTTPRequestHandler.

The HTTPRequestHandler is an extension that comes with the platform, so you don't need to install anything from forge, just need to add references to it. The GetRequest_Submit has a BinaryContent output, which is what you need.


I think you are going to run into a problem with those URLs. When I click them, I'm redirected to the nat. geo. home page. The server is probably defending against external linking. But, for now, just try to use the API to retrieve the contents of the URL, and if you run into problems get back to me.

Thanks for all the help Leonard! I'll try out GetRequest_Submit. That looks like what I really need here. Also the URL I provided is just an example, the actual image URLs I am using are hosted on an Amazon Web Services account.