From e84ba4d69ad54cfac6530cca9ca61fd816277544 Mon Sep 17 00:00:00 2001 From: Victor Pegado Date: Tue, 23 Feb 2016 14:20:41 +0100 Subject: [PATCH] fix binary files for ie11 --- angular-file-directive.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/angular-file-directive.js b/angular-file-directive.js index 148428e..98028b2 100644 --- a/angular-file-directive.js +++ b/angular-file-directive.js @@ -20,7 +20,13 @@ angular.module('ngFile', []) var body = e.target.result; // Base64 Encode file of type other than 'text' if (!isText) { - body = btoa(body); + var binary = ""; + var bytes = new Uint8Array(body); + var length = bytes.byteLength; + for (var i = 0; i < length; i++) { + binary += String.fromCharCode(bytes[i]); + } + body = btoa(binary); } // Compile data from file files.push({ @@ -42,7 +48,7 @@ angular.module('ngFile', []) if (isText) { reader.readAsText(file); } else { - reader.readAsBinaryString(file); + reader.readAsArrayBuffer(file); } }); });