diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 196447fe31..8a9224d104 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3613,13 +3613,18 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentDataURI', { return ''; } let buf = await OS.File.read(path, {}); - let bytes = new Uint8Array(buf); - let binary = ''; - let len = bytes.byteLength; - for (let i = 0; i < len; i++) { - binary += String.fromCharCode(bytes[i]); - } - return 'data:' + this.attachmentContentType + ';base64,' + btoa(binary); + buf = new Uint8Array(buf).buffer; + return new Promise((resolve, reject) => { + let blob = new Blob([buf], { type: this.attachmentContentType }); + let reader = new FileReader(); + reader.onloadend = function () { + resolve(reader.result); + } + reader.onerror = function (e) { + reject("FileReader error: " + e); + }; + reader.readAsDataURL(blob); + }); } }); diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 571cf60c77..433ac3d89d 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -831,13 +831,18 @@ Zotero.File = new function(){ } var buf = await OS.File.read(file, {}); - var bytes = new Uint8Array(buf); - var binary = ''; - var len = bytes.byteLength; - for (let i = 0; i < len; i++) { - binary += String.fromCharCode(bytes[i]); - } - return 'data:' + contentType + ';base64,' + btoa(binary); + buf = new Uint8Array(buf).buffer; + return new Promise((resolve, reject) => { + let blob = new Blob([buf], { type: contentType }); + let reader = new FileReader(); + reader.onloadend = function () { + resolve(reader.result); + } + reader.onerror = function (e) { + reject("FileReader error: " + e); + }; + reader.readAsDataURL(blob); + }); };