我寫的函數,將Base64字符串轉換爲Base64十六進制字符串,現在它被正確地轉換爲顯示爲BLOB png圖像......但問題是當我在數據庫瀏覽器中爲SQLite打開字段時,它將此轉換值寫入文本,並必須寫爲二進制(以便圖像將被識別並顯示時,我選擇圖像在DB瀏覽器SQLIte ...所以問題是我怎麼能Base64十六進制字符串插入SQLite3數據庫爲二進制?
這裏是我的代碼插入:
/* GET - channels_logo */
for (var i in rows) {
/* WRITE - table channels_logo */
db.prepare('INSERT INTO channels_logo (logo_id, logo_channel, logo_png) VALUES
("'+rows[i].id+'", "'+rows[i].channel+'", "'+(base64toHex(new Buffer(rows[i].logo).toString()))+'")').run();
};
function base64toHex(base64) {
/* DEFINE - variables */
var raw = atob(base64);
var HEX = '';
for (i = 0; i < raw.length; i++) {
var _hex = raw.charCodeAt(i).toString(16)
HEX += (_hex.length==2?_hex:'0'+_hex);
};
return HEX.toUpperCase();
};
[![Using this insert code is inserted as Text:][1]][1]
https://i.stack.imgur.com/iZ2A1.jpg
[![And needs to be binary inserted and now it looks ok (i just erase text and copy text inserted into binary and now it works)][1]][1]
https://i.stack.imgur.com/ZzGTU.jpg
所以我看到的SQLite3顯示插入Base64的十六進制爲文本而不是二進制。 ..我需要寫在插入語句插入它爲二進制?
可能的[客戶端Javascript中的Base64編碼和解碼]重複(https://stackoverflow.com/questions/2820249/base64-encoding-and-decoding-in-client-side-javascript) – pabrantes
可能的重複[如何在HTML中顯示Base64圖像?](https://stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html) – damd
我認爲這是不重複我需要從MySQL讀取blob base64文本圖像,然後將其保存到sqlite3數據庫,以便它可以在sqlite3數據庫中顯示圖像作爲圖像不是文本 – John