TagSpaces is an offline, open source, document manager with tagging support
Issue TS204 - Add existing file on Android
miroopb4d492c28df2
diff --git a/data/cordova/cordova.api.js b/data/cordova/cordova.api.jsindex 8c2eb0d0e..3aeb979f1 100644--- a/data/cordova/cordova.api.js+++ b/data/cordova/cordova.api.js@@ -624,11 +624,16 @@ define(function(require, exports, module) {function(entry) {entry.createWriter(function(writer) {+ var string = content.split(';base64,');+ var type = string.length > 1 ? string[0].split(':')[1] : '';+ var newContent = string.length > 1 ? string[1] : string[0];+ var data = TSCORE.Utils.b64toBlob(newContent, type, 512);writer.onwriteend = function(evt) {//resolve(fsRoot.fullPath + "/" + filePath);resolve(isFileNew);};- writer.write(content);+ //writer.write(content);+ writer.write(data);},function() {reject("error creating writter file: " + filePath);@@ -658,7 +663,7 @@ define(function(require, exports, module) {* @returns {Promise.<Success, Error>}*/function saveTextFilePromise(filePath, content, overWrite) {- console.log("Saving file: " + filePath);+ console.log("Saving TEXT file: " + filePath);// Handling the UTF8 support for text filesvar UTF8_BOM = "\ufeff";if (content.indexOf(UTF8_BOM) === 0) {@@ -681,7 +686,8 @@ define(function(require, exports, module) {*/function saveBinaryFilePromise(filePath, content, overWrite) {console.log("Saving binary file: " + filePath);- var dataView = new Int8Array(content);+ //var dataView = new Int8Array(content);+ var dataView = content;return saveFilePromise(filePath, dataView, overWrite);}diff --git a/data/js/core.ui.js b/data/js/core.ui.jsindex 692a89a85..c0955508e 100644--- a/data/js/core.ui.js+++ b/data/js/core.ui.js@@ -70,7 +70,11 @@ define(function(require, exports, module) {addFileInputName = decodeURIComponent(file.name);var reader = new FileReader();reader.onload = onFileReadComplete;- reader.readAsArrayBuffer(file);+ if (isCordova) {+ reader.readAsDataURL(file);+ } else {+ reader.readAsArrayBuffer(file);+ }});$('#openLeftPanel').click(function() {diff --git a/data/js/utils.js b/data/js/utils.jsindex 4063aad96..e0fa558d3 100644--- a/data/js/utils.js+++ b/data/js/utils.js@@ -111,6 +111,37 @@ define(function(require, exports, module) {return _.uniq(TSCORE.selectedFiles);}+ /**+ * Convert 64bit url string to Blob+ * @name b64toBlob+ * @method+ * @memberof TSCORE.Utils+ * @param {string} b64Data - the 64bit url string which should be converted to Blob+ * @param {string} contentType - content type of blob+ * @param {int} sliceSize - optional size of slices if omited 512 is used as default+ * @returns {Blob}+ */+ function b64toBlob(b64Data, contentType, sliceSize) {+ contentType = contentType || '';+ sliceSize = sliceSize || 512;++ var byteCharacters = atob(b64Data);+ var byteArrays = [];++ for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {+ var slice = byteCharacters.slice(offset, offset + sliceSize);+ var byteNumbers = new Array(slice.length);+ for (var i = 0; i < slice.length; i++) {+ byteNumbers[i] = slice.charCodeAt(i);+ }+ var byteArray = new Uint8Array(byteNumbers);+ byteArrays.push(byteArray);+ }+ var blob = new Blob(byteArrays, {type: contentType});+ return blob;+ }++exports.arrayBufferToDataURL = arrayBufferToDataURL;exports.base64ToArrayBuffer = base64ToArrayBuffer;exports.dataURLtoBlob = dataURLtoBlob;@@ -124,5 +155,6 @@ define(function(require, exports, module) {exports.isVisibleOnScreen = isVisibleOnScreen;exports.getRandomInt = getRandomInt;exports.getUniqueSelectedFiles = getUniqueSelectedFiles;+ exports.b64toBlob = b64toBlob;});