Image Upload In Sqlite Database Android
Solution 1:
I think an easier solution would be to save on Database only the path of your Image as given by SELECT_PICTURE
Intent. Anyway, if you're forced to save the image contents, I believe the problem to be in line:
contentValues.put(DatabaseHelper.IMAGE, String.valueOf(image));
Because you're passing to a byte column (BLOB) a simple String. BLOBs are somehow tricky, you can't handle them as if they were simple strings. Try to do the insert like this, with bind statement:
SQLiteStatementinsertStmt= db.compileStatement("INSERT INTO ....");
insertStmt.clearBindings();
insertStmt.bindBlob(3, (byte[])yourImageData);
insertStmt.executeInsert();
See this question to see other blob handling techniques such as Bitmap.CompressFormat
and base64 encoding/decoding.
Solution 2:
You should not save image or heavy data in sqlite, as it reduce the performance. You can save image file path in database, and you want to do any operation on image, you can get the image using -File file = new File(SAVED_IMAGE_FILE_PATH);
Post a Comment for "Image Upload In Sqlite Database Android"