cancel
Showing results for 
Search instead for 
Did you mean: 

process instances diagram from REST-API

yerbol777
Champ in-the-making
Champ in-the-making
Hello,

I am trying to draw process diagram by getting respone from Activiti Rest API with ajax: GET runtime/process-instances/{processInstanceId}/diagram
And getting repsponse of data in image/png. Now question is how to convert data to image format using ajax?

Tried this:
var data = "data:image/png;" + hr.responseText;
document.getElementById("image").src = data;
not working…

Response starts with: PNG … (i've put as attachment)


Thank you. 

5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
"And getting repsponse of data in image/png. Now question is how to convert data to image format using ajax?"

Not sure what you mean … image/png _is_ an image format.

yerbol777
Champ in-the-making
Champ in-the-making
Thank you for your reply,
response i put in txt attachment file, i am not able to convert response to png format using ajax.
GET runtime/process-instances/{processInstanceId}/diagram

yerbol777
Champ in-the-making
Champ in-the-making
If i check response, it is not in byte format, it shoud be in byte format right?
Maybe i am doing smth wrong?

cavdar
Champ in-the-making
Champ in-the-making
Hi yerbol777,
I implemented following method to get the image via Activiti-REST-API:
<java>
  public InputStream invokeGetInputStream()
  {
    HttpGet getMethod = new HttpGet( buildURI() );
    CloseableHttpResponse httpResponse = null;
    try
    {
      httpResponse = httpClient.execute( getMethod );
      final HttpEntity responseEntity = httpResponse.getEntity();
      int statusCode = httpResponse.getStatusLine().getStatusCode();
      if( statusCode == HttpStatus.SC_OK )
      {
        InputStream content = IOUtils.toBufferedInputStream( responseEntity.getContent() );
        return content;
      }
      return null;
    }
    catch( Exception e )
    {
      throw new MyOwnException( e );
    }
    finally
    {
      HttpClientUtils.closeQuietly( httpResponse );
    }
  }
</java>

Then save the InputStream to a file:

<java>
{
      InputStream bufferedInputStream = IOUtils.toBufferedInputStream( inputStream );
      byte [] byteArray = IOUtils.toByteArray( bufferedInputStream );
      InputStream temp1 = new ByteArrayInputStream( byteArray );
      String selectedTestType = (String)getComboBoxTestType().getSelectedItem();
      File imgFile = new File( environmentConfig.getTestOutputsFile().getAbsolutePath(),
                                          ( selectedTestType + "." +
                                            userTaskThread.getCurentTaskDefinitionKey() +
                                            ".jpg" ) );
      FileUtils.copyInputStreamToFile( temp1, imgFile );
      temp1.close();
}
</java>

yerbol777
Champ in-the-making
Champ in-the-making
hi Cavadar,
The problem is i am integrating activiti with asp.net mvc site. I should call rest from csharp and convert to jpg or png.
But finally i found solution, i just put like : < img src="http://localhost:8080/activiti-rest/service/runtime/process-instances/{processInstanceId}/diagram" / > and it is working.

Thank you for all.