1. Converting a string string into a Blob object
// Convert a string into a Blob object var New Blob (["Hello world!" ], { ' Text/plain '}); Console.info (BLOB); Console.info (Blob.slice (1, 3, ' Text/plain '));
2. Convert Typearray to Blob object
//convert Typearray to Blob objectvarArray =NewUint16array ([97, 32, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]);//Test Success//var blob = new blob ([array], {type: "Application/octet-binary"});//Test SuccessvarBlob =NewBlob ([array]);//to read a Blob object as a stringvarReader =NewFileReader (); Reader.readastext (BLOB,' Utf-8 '); Reader.onload=function(e) {console.info (reader.result);//a Hello world!}
3, Convert Blob object to string string, use FileReader's Readastext method
// Convert a string into a Blob object var New Blob ([' Chinese string '], { ' Text/plain '}); // Convert a Blob object to a string var New ' utf-8 'function (e) { console.info (reader.result);}
4. Convert BLOB objects to Arraybuffer, using FileReader's Readasarraybuffer method
//Convert a string into a Blob objectvarBlob =NewBlob ([' Chinese string '], {type:' Text/plain '});//convert BLOB objects to ArrayBuffervarReader =NewFileReader (); Reader.readasarraybuffer (BLOB); Reader.onload=function(e) {console.info (reader.result);//ArrayBuffer {} //frequently encountered exceptions uncaught rangeerror:byte length of Int16array should be a multiple of 2 //var buf = new Int16array (reader.result); //Console.info (BUF); //convert Arraybufferview to blob varBUF =NewUint8array (Reader.result); Console.info (BUF); //[228, 184, 173, he, 135 , 229, 173, 151, 231, 172, 166, 228, 184, 178]Reader.readastext (NewBlob ([buf]), ' Utf-8 '); Reader.onload=function() {console.info (reader.result);//Chinese string }; //convert Arraybufferview to blob varBUF =NewDataView (Reader.result); Console.info (BUF); //DataView {}Reader.readastext (NewBlob ([buf]), ' Utf-8 '); Reader.onload=function() {console.info (reader.result);//Chinese string };}
For Blob objects, refer to: http://www.cnblogs.com/tianma3798/p/4293660.html
HTML5 blob to convert between Arraybuffer, Typearray, and string strings