Image upload component

I’ve successfully followed the examples on the forum to upload an image into an SQL database then I am trying to retrieve the saved image from database and show it in image component in perspective. I tried different ways but none of them seems working. In db dataType is varbinary(Max).
I am trying;
query as:
SELECT CAST(’’ as xml).value(‘xs:base64Binary(sql:column(“file_stream”))’, ‘varchar(MAX)’) from
Files where name =‘Photo.png’

path=“selectphoto”
v=system.db.runNamedQuery(path)
return {‘contentType’:‘image/png’,‘bytes’:v}

Thanks in advance.

Please use the </> code formatting button when posting code. You can edit your post with the pencil icon button.

@pturmel made a module for fetching blobs from a database

2 Likes

The above is wrong. v is not an array of bytes. It is a dataset. You need to access the row/column containing the blob. If the first row, as typical, your code should look like this:

ds = system.db.runNamedQuery(path)
v =  ds.getValueAt(0, 'myBlobColumnName')
return {'contentType':'image/png','bytes':v}

Or switch your named query type to be a ‘scalar’ query.

3 Likes

thanks it’s working