我在将图像转换为 base64 字符串以通过 xml 传输时遇到一些问题。我在拍摄照片时将图像位置(完整路径)存储到数据库中,现在我正在尝试上传它。我正在尝试读取我在(results.rows.item(i).PictureFile) 中的文件,然后将其转换为base64。下面是我用来执行此操作的代码部分。任何人都可以做的任何帮助都会很棒。
function submitPhoto(PhotoId)
{
g_submitXML = '';
var err = '';
var errorsArr = $.makeArray(err);
window.g_submitXML = '';
window.g_submitXML = window.g_submitXML + '';
window.g_submitXML = window.g_submitXML + '';
window.g_submitXML = window.g_submitXML + '';
console.log("successfully started the xml with: " + window.g_submitXML);
var db = window.openDatabase("MobileData", "3.0", "MobilePhoneData", 1000000);
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM MobilePhotos WHERE PhotoId = ' + PhotoId + '',
[],
function(tx, results) {
console.log("HIT THE RESULTS PHOTO FUNCTION");
var len = results.rows.length;
console.log("Photo table: " + len + " rows found.");
for (var i = 0; i < len; i++)
{
window.g_submitXML = window.g_submitXML + '<EMBEDDED_FILE _Type="JPEG" _Name="Image_' + i + '"';
window.g_submitXML = window.g_submitXML + '_Extension=.jpg _EncodingType="Base64" _ImageOrientation="' + results.rows.item(i).PictureLocationDesc + '">';
window.g_submitXML = window.g_submitXML + '<DOCUMENT>';
var reader = new FileReader();
console.log(results.rows.item(i).PictureFile);
//I am having problems with the line below
window.g_submitXML = window.g_submitXML + reader.readAsDataURL(fileSystem.root.getFile(results.rows.item(i).PictureFile));
//I am having problems with the line above ^
window.g_submitXML = window.g_submitXML + '</DOCUMENT>';
window.g_submitXML = window.g_submitXML + '</EMBEDDED_FILE>';
}
},
console.log("ERROR"));
});
}
我已经在我遇到问题的行上方和下方发表了评论。
谢谢!