Skip to content

Commit 1502849

Browse files
authored
Merge pull request #1672 from processing/bug/non-english-names
[#1620] adds toBinary function to File Uploader
2 parents fc46598 + dbc05ff commit 1502849

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: client/modules/IDE/actions/uploader.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ function localIntercept(file, options = {}) {
3131
});
3232
}
3333

34+
function toBinary(string) {
35+
const codeUnits = new Uint16Array(string.length);
36+
for (let i = 0; i < codeUnits.length; i += 1) {
37+
codeUnits[i] = string.charCodeAt(i);
38+
}
39+
return String.fromCharCode(...new Uint8Array(codeUnits.buffer));
40+
}
41+
3442
export function dropzoneAcceptCallback(userId, file, done) {
3543
return () => {
3644
// if a user would want to edit this file as text, local interceptor
@@ -94,7 +102,12 @@ export function dropzoneCompleteCallback(file) {
94102
originalFilename: file.name
95103
};
96104
// console.log(json, JSON.stringify(json), JSON.stringify(json).replace('"', '\\"'));
97-
inputHidden += `${window.btoa(JSON.stringify(json))}" />`;
105+
let jsonStr = JSON.stringify(json);
106+
// console.log(json, jsonStr, jsonStr.replace('"', '\\"'));
107+
108+
// convert the json string to binary data so that btoa can encode it
109+
jsonStr = toBinary(jsonStr);
110+
inputHidden += `${window.btoa(jsonStr)}" />`;
98111
// document.getElementById('uploader').appendChild(inputHidden);
99112
document.getElementById('uploader').innerHTML += inputHidden;
100113

0 commit comments

Comments
 (0)