Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion client/modules/IDE/actions/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down