How to write UTF-8 or Base64 data into a file (jpg/doc/pdf) on local storage(sdcard) in Phonegap

后端 未结 3 2139
渐次进展
渐次进展 2021-02-09 07:14

I am getting byte array like var byteArr=[12,-123,43,99, ...] from API, Then I am converting it into UTF-8 String by

     var utf8_str = String.fromCharCode.appl         


        
3条回答
  •  半阙折子戏
    2021-02-09 07:38

    I have found solution to create file by byte array in Phonegap.

    In phonegap, Text and Binary data are supported for Android and iOS to write into file. So I have convert BYTE array to BINARY array, then write by FileWriter.

     var byteArr=[12,-123,43,99, ...] ;
     var UTF8_STR = new Uint8Array(byteArr);  // Convert to UTF-8...                
     var BINARY_ARR=UTF8_STR.buffer;         // Convert to buffer...    
    

    Then pass 'BINARY_ARR' to FileWriter to write in file.

     function gotFileWriter(writer) {
         writer.onwriteend = function(evt) {
         console.log("File write successfully....");        
       };
       writer.write(BINARY_ARR);   
     }
    

    Have a nice day.. :)

提交回复
热议问题