How To Store A Pdf File In Sqlite Data Base In Android
Solution 1:
You can. Simply read all the bytes of the pdf file and store in the blob field of sqlite db.
Solution 2:
One solution is to use blob and to store the raw data of the file as column in the db.
Other solution which i think is better to store the files on the Internal Storage and in the db just to store the file paths. Internal storage is private for your application so no one will have access to the files. But be careful in both cases the files are stored on the phone storage and people can find themselves in situation when there is no more phone storage.
Solution 3:
AFAIK Sqlite support the BLOB datatype, I used BLOB for store images into MySql databases, I think you can do the same thing reading the file content and storing that into a BLOB column in SQLite
Solution 4:
You can use a BLOB datatype to store a PDF file in the database but that wouldnt be my suggestion since you are using SQLlite tough its possible. Some people say it's a dirty way to store binary files in a database. Large databases will result in slower queries.
My solution would be to store a PDF file in a directory and use a string pointer to the file name. This will result in faster queries and a smaller database. Only downside is that you have to write functionality to rename duplicate entries and delete files from the file system when you delete an entry.
Please comment if (large) binary files in databases make the database slower...
Post a Comment for "How To Store A Pdf File In Sqlite Data Base In Android"