@@ -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+
3442export 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