首页 > 解决方案 > Replace an image resource on a jasperserver via Java REST API v7.2.0

问题描述

I am trying to upload reports and resources for these reports via the java rest api v7.2.0 on a jasperserver.

I found that upload an image could be done like so :

RestClientConfiguration configuration = new RestClientConfiguration("http://127.0.0.1:8082/jasperserver");
configuration.setLogHttp(true);
configuration.setLogHttpEntity(true);
configuration.setJrsVersion(JRSVersion.v6_1_0);
configuration.setRestrictedHttpMethods(false);

JasperserverRestClient client = new JasperserverRestClient(configuration);
Session session = client.authenticate("jasperadmin", "jasperadmin");

session.resourcesService().resource("/images").uploadFile(new File("logo.png"), ClientFile.FileType.img, "logo.png", "logo.png"));

But this exact same code fail if the image already exists, but I would like to overwrite the image, in case it must be updated.

The problem is that I can't delete then upload again the image as if it is referenced in a report it will generate and error.

How can I replace an already present image via the rest api ?

标签: javarestjasperserver

解决方案


Ok, I found how to « update » a resource file on a jasper server using the rest api.

If someone go check the definition of the rest api, you could see that they use POST for creation and PUT for update.

The problem is that the java rest client library only provide a method that will only use POST, you have to find a way to had a method to switch the call of post by a call for put.


推荐阅读