將大型二進制文件直接保存到數據庫是非常罕見的。更常見的方法是將圖像保存到文件並將路徑保存到數據庫。
見討論的幾個:
How to store image in SQLite database
Android Save images to SQLite or SDCard or memory
saving image into SQLITE?
我假設你寧願保存到數據庫的引用,我的回答是基於這個。
看看這裏的例子: http://docs.smartface.io/html/T_SMF_IO_File.htm
SMF.Multimedia.startCamera({
cameraType : 1, //rear camera
resolution : 2, //large resolution
autoFocus : true,
onStart : function() {}, //do nothing
onCapture : function (e) {
var photoFile = new SMF.IO.File(e.photoUri); //the full URI is given
var destination = SMF.IO.applicationDataDirectory + //predefined path already containing separator at the end
"data" + SMF.IO.pathSeperator + "tbl1" +
SMF.IO.pathSeperator + photoFile.name; //name gives file name with extension
var targetFile = new SMF.IO.File(destination);
if(!targetFile.exists) {
if(photoFile.move(destination)) { //if moved successfully
//photoFile nativePath has been updated
Data.execute("Insert into tbl1 (image) values(?)",
photoFile.nativePath); //records reference to database
}
}
},
onCancel : function() {}, //do nothing
onFailure : function() {}
//do nothing
});
您將節省的「目的地」變量(指上面的例子),以數據庫和取一部分,那麼會是這樣:
Pages.PgMain.rptArticles.Image1.image = SMF.Image(records.rows[e.rowIndex][3]);