How to upload screenshots in base64 or blob format with axios + vue-cropper

as an aside, cropper screenshots support obtaining data in base64 and blob formats. What"s the difference between these two? if I get file from the background in the following ways, which format is suitable

HttpServletRequest request
List<MultipartFile> files = ((MultipartHttpServletRequest)request).getFiles("file");

main topic: after vue-cropper obtains the information of the captured image, how does the foreground upload it to the background, and the backend can receive it in the above way

the partial code of the axios request method I encapsulated is as follows

  updateUserIcon(){
    return request({
      url:"user/updateUserIcon",
      method:"post",
    })
  }

the parameters used to be passed to the background are as follows. Note: data uses qs formatted in the global, and finally uses the same format as parmas (as if saying more nonsense)

.
parmas(data):{
 openID:"123465"
}

at this time, I don"t know if it"s a file, and I"m even more confused if it"s in base64 or blob format. I hope some bosses will talk about it carefully, otherwise the novice will not be able to accept

.

according to your background code, the background file should be the receiving file, not base64
this is the code I sent to Qiniu at that time, maybe you can refer to

  async saveBack() {
    let file = ioUtil.dataURLtoFile(this.backCropper.getCroppedCanvas().toDataURL());
    this.user.background = URL.createObjectURL(file);
    this.uploadBackLoading = true;
    let result = await this.upload(file, "back");
    this.uploadBackLoading = false;
    if (result.status !== 200) {
      this.$notify({message: result.message});
      return;
    }
    this.isShowTailoringBack = false;
  }
  
  

here is the code for ioUtil.dataURLtoFile

  dataURLtoFile(dataurl, filename = 'file') {
    let arr = dataurl.split(',');
    let mime = arr[0].match(/:(.*?);/)[1];
    let suffix = mime.split('/')[1];
    let bstr = atob(arr[1]);
    let n = bstr.length;
    let u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n)
    }
    return new File([u8arr], `${filename}.${suffix}`, {type: mime})
  },
  
  
  
Menu