Transfer flie blob

function fileChange(file) {
  let reader = new FileReader();
  let rs = reader.readAsArrayBuffer(file);
  let blob = null;
  reader.onload = (e) = > {
    if (typeof e.target.result === 'object') {
      blob = new Blob([e.target.result])
    } else {
      blob = e.target.result
    }
    console.log(Object.prototype.toString.call(blob)); }}Copy the code

Transfer the blob base64

function blobToDataURI(blob, callback) {
  var reader = new FileReader();
  reader.readAsDataURL(blob);
  reader.onload = function(e) {
    callback(e.target.result);
  };
}
Copy the code

Convert Base64 to a file

dataURLtoFile(dataurl, filename) {
  var arr = dataurl.split(",");
  var mime = arr[0].match(/ : (. *?) ; /) [1];
  var bstr = atob(arr[1]);
  var n = bstr.length;
  var u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new File([u8arr], filename, { type: mime });
}
Copy the code