cancel
Showing results for 
Search instead for 
Did you mean: 

Help:how to show PNG image of a process using REST api?

jolly_ian
Champ in-the-making
Champ in-the-making
I want to create an HTML website using the REST APIs with JQuery and Ajax. Till now every thing works fine except that I cannot display the image of a process in HTML client.

The problem originates from the fact that the rest API itself is the url to the image, but when I set the source of the image to this url, it fails to display, because there is no authentication and thus the Rest server does not reply correctly.

When I do the request in JQuery, I do can get the binary data of the image, because JQuery helps me add an authentication header to the request. I have tried the BASE-64 method that may display binary data directly in HTML, but the PNG that the Activiti server returned was too big to be displayed.

Is there any one who has successfully displayed the PNG image with the REST APIs?

Thanks for your attention. Smiley Happy
8 REPLIES 8

jbarrez
Star Contributor
Star Contributor
I don't understand how an image can be 'too big' to be displayed? Does the server return wrong data?

That being said, Tijs is currently working on integrating a javascript only process diagram viewer in Explorer, might be worthwhile to check that out.

jolly_ian
Champ in-the-making
Champ in-the-making
I don't understand how an image can be 'too big' to be displayed? Does the server return wrong data?

That being said, Tijs is currently working on integrating a javascript only process diagram viewer in Explorer, might be worthwhile to check that out.

Thanks for your quick reply!~ Too big means that even though some browsers like Chrome is able to display image that written in BASE-64 code, this code can not be too long. Unfortunately, images of processes of Activiti are beyond that limitation.

What I want to know is quite simple: is there any effective javascript or HTML code that can let the browser display the PNG image generated from REST APIs?

Thanks again~

jbarrez
Star Contributor
Star Contributor
Ok, I see your problem

One really ugly hack which might work is to load your image with something like image.src = 'http://'+user+':'+pass+'@'+someUrl
But that's not really nice of course as it exposes the user and pass in the open. I did not test this though.

But it raises an interesting question: what is a good solution for this? Definitely not the way it is implemented now.
One way could be we need tokens in the url. Or something else … I'll discuss it with the team.

jbarrez
Star Contributor
Star Contributor
Okay, there are two use cases here:

- rest is used by another service (not html): then the security is importent
- rest is used from html/js: in this case the current solution is not workable. So we will remove security from that specific operation.

Hey Facebook also exposes your pics if you know the url! 😉

jolly_ian
Champ in-the-making
Champ in-the-making
Okay, there are two use cases here:

- rest is used by another service (not html): then the security is importent
- rest is used from html/js: in this case the current solution is not workable. So we will remove security from that specific operation.

Hey Facebook also exposes your pics if you know the url! 😉

Haha~ I see. You mean that the REST APIs were originally designed for another service, not HTML. This is the reason why I cannot load the image in my browser.

Thanks for your kind reply! I hope you could let me know if this security problem is solved. Smiley Happy

jbarrez
Star Contributor
Star Contributor
Well, we've removed security from that service on master. So in 5.12 it will be possible to fetch without any security.

sergiolog10
Champ in-the-making
Champ in-the-making
I have a similar problem with the URL /repository/process-definition/{id}/image. I'd like the use the URL from the processDefinition JSON fetch and let the browser show the image by adding /image to the URL it already have. That URL is still protected, any chance of having it opened ?

Thanks,

jbarrez
Star Contributor
Star Contributor