Using SQL images (byte arrays) in reports

Hi,
i need to display images that are stroed as byte arrays in MSSQL in a Report. From what ive seen so far, the image component in reports needs a path as key. Is there a way to display byte array images in reports? I know how to do it in perspective.

There was a similiar post 2 years ago without solution:

Im thankful for any input
Luca

Set your byte array as a parameter or data key value (via script or query) and then bind the image component to that key, and it should "just work".

1 Like

Hi, i tried that already and it doesnt work. Not sure if i am missing something.

The bytecode is saved in "emptyCellForPic". Here is what it looks like in preview:

Maybe i have the bytecode in wrong format?
Thank you.

What's the actual source of that data? You want a raw Java byte array that contains the binary data for an image (in JPG, BMP, PNG, or a few other formats), not any kind of encoded data.

1 Like

The image (JPG) is uploaded via the perspective FileUpload Component and a "onFileReceived" action wich utilizes a skript. In that script i use event.file.getBytes() to get the imagebytes and save that to a database (named Query). In the report i query that db for the bytevalue.

And the DB column is a BLOB type, and nothing's getting truncated? What does the data look like in the XML preview in the report designer?

1 Like

Image Type (MSSQL)
XML Preview:


It looks like there's some double encoding happening - you shouldn't be getting that leading XML like string if you're uploading the raw image data. Can you post your file upload script?

1 Like

def runAction(self, event):
	# Upload des Files (Bild im jpg Format über File Upload Component, zuordnung jpg Bytes zu variable image
	image = event.file.getBytes()
	
	args =	{
		"assetID": self.view.params.assetID,
		"categoryID": 1,
		"imageName": self.parent.parent.getChild("txtf_nameInput").props.text,
		"imageByte": image
	}
	
	resp = system.db.runNamedQuery("INSERT/addPicOld",args)
	
	self.parent.parent.getChild("img_image").custom.imageID = resp.getValueAt(0, "imageID")

The Select Query might be the issue (gets me the data from the db to the report)

select imageBytes
from  images 
where  imageID = :imageID 
FOR XML AUTO, BINARY BASE64;

Looks like this if i remove "FOR XML AUTO, BINARY BASE64;"

That looks more like what I would expect. Does that show up correctly in the image component?

1 Like

Nope :confused:

I found my issue:

If i dont take the value at (0,0) and instead just use the result my Select Query gives me, its shown properly.

#data['test'] = imageBytes.getValueAt(0,0)
data['testraw'] = imageBytes

I assigned the select results to "imageBytes" and then took the value at first row, first column. Somehow that was the problem, if i just use the query result as a whole it works ? :smiley:

If you know why thats works im interested in that.

anyway, thank you very much for your Help!!

Huh, maybe we're automatically doing something in the image component with the (presumably) dataset we're now getting, but I would've thought the same as you, that the right thing to do would be to either unpack in the script or make your query to fetch the image data a scalar query. Either way, working is working :smile:

1 Like