Automation Professionals' Blob Server Module

After you switch back to varbinary, make sure whatever inserts into the table pushes bytes, not a string.

This is what was used to populate the table...

INSERT INTO [dbo].[FILLER_HELP_FILES_TEST]
           ([file_id]
           ,[file_blob])
		SELECT 'Check Scale.pdf'
           ,BulkColumn
		FROM 
			OPENROWSET(BULK 'C:\Projects\CRI\Fillers\CLX\Ignition\HelpFiles-Filler\Check Scale.pdf', SINGLE_BLOB)
		AS BLOB;

I have no idea how that SQL Server-specific function works, sorry.

A script like this in the designer would be typical:

blob = system.file.readFileAsBytes("path/to/some/someName.pdf")
fname = "someName.pdf"
sql = """INSERT INTO some_table (file_id, file_blob) VALUES (?, ?)"""
print system.db.runPrepUpdate(sql, [fname, blob])

Should print 1 for the DB return value.

The NQ SQL should be just:

SELECT 'application/pdf' AS "ContentType", file_blob AS "Content"
WHERE file_id = :file_id

Thanks

Varbinary column type made the content results in the NQ tester look a bit different, but still no joy in the browser.

I'll give your script a shot.

Except that it needs the table name :slightly_smiling_face:

SELECT file_blob as "Content", 'application/pdf' as "ContentType"
FROM FILLER_HELP_FILES_TEST
WHERE file_id = :file_id
1 Like

I just remembered:

Make sure there's a unique index on file_id, since you aren't looking up by primary key. If the NQ yields more than one row, you get nothing.

1 Like

Thank you.
As an update, using system.file.readFileAsBytes() and system.db.runPrepUpdate() solved the problem. Apparently the sql server OPENROWSET() function, at least in the way that I used it, does not load the data in a manner that your module expects.
Thanks so much for your module and support!

1 Like

How can I 'clean-up' all the resources (URL) that module has created?
Thank you.

Delete the rows from your database. This module doesn't create any content. It just presents what you have in your DB. You put content there. You have to take it out.

Thank you very much, I didn't notice that.