Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting blob into sqlite from safari browser using html5

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.

like image 690
Piwacket Avatar asked Nov 14 '22 11:11

Piwacket


1 Answers

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...');
like image 123
CL. Avatar answered Nov 16 '22 04:11

CL.