I need to load/insert a pdf to a blob in my sqlite db, I'm using html5 and javascript.
I am using the sqlite db locally using html5 and safari browser, have a db going beautifully... just need to know how to insert a blob into the db from a pdf file on the same, obviously because it's local, box.
I imagine the sql would be something like insert into mytable columns (myblob) values ("/documents/myfile.pdf");
Any advice or direction is greatly appreciated. Thanks.
To read the PDF from disk, you would use the FileReader
interface of the File API. See http://www.html5rocks.com/en/tutorials/file/dndfiles/ for a tutorial.
The WebSQL API does not have data types for accessing blobs, so you have to convert the file contents to a textual INSERT command.
In SQLite, a BLOB literal is a string containing hexadecimal byte values, prefixed with an x
, like this:
INSERT INTO mytable(myblob) VALUES(x'255044462d312e340d25e2e3cfd30d0a...');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With