From 570387823ec54f45dceb47d483d2981237c98844 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 12 Nov 2020 16:56:50 -0500 Subject: [PATCH] [#1620] adds toBinary function to File Uploader --- client/modules/IDE/actions/uploader.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client/modules/IDE/actions/uploader.js b/client/modules/IDE/actions/uploader.js index b62c0604ca..207411aa11 100644 --- a/client/modules/IDE/actions/uploader.js +++ b/client/modules/IDE/actions/uploader.js @@ -31,6 +31,14 @@ function localIntercept(file, options = {}) { }); } +function toBinary(string) { + const codeUnits = new Uint16Array(string.length); + for (let i = 0; i < codeUnits.length; i += 1) { + codeUnits[i] = string.charCodeAt(i); + } + return String.fromCharCode(...new Uint8Array(codeUnits.buffer)); +} + export function dropzoneAcceptCallback(userId, file, done) { return () => { // if a user would want to edit this file as text, local interceptor @@ -94,7 +102,12 @@ export function dropzoneCompleteCallback(file) { originalFilename: file.name }; // console.log(json, JSON.stringify(json), JSON.stringify(json).replace('"', '\\"')); - inputHidden += `${window.btoa(JSON.stringify(json))}" />`; + let jsonStr = JSON.stringify(json); + // console.log(json, jsonStr, jsonStr.replace('"', '\\"')); + + // convert the json string to binary data so that btoa can encode it + jsonStr = toBinary(jsonStr); + inputHidden += `${window.btoa(jsonStr)}" />`; // document.getElementById('uploader').appendChild(inputHidden); document.getElementById('uploader').innerHTML += inputHidden;