Jump to content
Changes to the Jaspersoft community edition download ×

Failing to load images (Byte data not found)


jbaker

Recommended Posts

Hello,

 

I have a couple images in a report and when I run it the following exception occurs:

 

net.sf.jasperreports.engine.JRException: Byte data not found at location : header-slice-wide.JPG

at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:467)

at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:175)

at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:477)

 

I've set the SUBREPORT_DIR parameter before running the report but this has not fixed the problem. How are embedded images handled?

 

Thanks,

 

 

John

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Hi!

The best way is to use iReport and the jasperserver plugin ...

Then, any image you drag&drop from the JS plugin view onto the report is reference by a repo:... url, which is then used for finding the image when running the report on the server.

Of course, this requires the image to be on the server - which it does, anyway, if you want to use it from JasperServer.

On the other hand, a repo: URL can't be accessed when you just run the report in iReport, only when running it via the plugin.

 

Sebastian

Link to comment
Share on other sites

Hi,

 

I've looked into this problem and concluded that images handling requires some work. The current implementation attempts to create a File object with the image name, which assumes the image resides in the current working directory:

 

JRLoader. public static Object loadObjectFromLocation(

String location,

ClassLoader classLoader,

URLStreamHandlerFactory urlHandlerFactory

) throws JRException

{

 

// Cut

 

File file = new File(location);

if (file.exists() && file.isFile())

{

return

 

This isn't really a very useful solution for a web based environment. I've worked around the problem by writing my own renderer that has a static directory in which images will be found, however this is also over kill.

 

The solution is for the default image loader (from files) to make use of a parameter that can be passed into the report. Very much like the subreport parameter, this parameter would state where the images have been stored.

 

I take your point concerning jasper server but the company I am working for wanted their own version, and to be honest, we should probably open source it as it's rather smart!

 

Is there any chance the image directory parameter could be added in a future release?

 

Thanks,

 

 

John

Link to comment
Share on other sites

  • 2 weeks later...

You can manually create an image directory parameter and use it the source expression of each image.

 

Also, if you look at the entire loadObjectFromLocation method you will see that it also attempts to resolve the location as a URL or a classloader resource. Therefore, you can customize the way images are loaded by providing URL handlers or custom classloaders.

 

If you have concrete improvement suggestions, please log them as feature requests.

 

Regards,

Lucian

Link to comment
Share on other sites

  • 7 years later...
  • 1 year later...
Error 500: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is net.sf.jasperreports.engine.JRException: Byte data not found at : ..//reports//images//xyz.gif

 

The above error is fixed by using the imageExpression

 

getClass().getResource("META-INF/resources/......../themes/default/images/xyz.png").openStream()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...