@@ -31,6 +31,14 @@ function localIntercept(file, options = {}) {
31
31
} ) ;
32
32
}
33
33
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
+
34
42
export function dropzoneAcceptCallback ( userId , file , done ) {
35
43
return ( ) => {
36
44
// if a user would want to edit this file as text, local interceptor
@@ -94,7 +102,12 @@ export function dropzoneCompleteCallback(file) {
94
102
originalFilename : file . name
95
103
} ;
96
104
// 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 ) } " />` ;
98
111
// document.getElementById('uploader').appendChild(inputHidden);
99
112
document . getElementById ( 'uploader' ) . innerHTML += inputHidden ;
100
113
0 commit comments