The video is saved in Base64 format after interception, which cannot be uploaded to the server. It needs to be converted
DataURLtoFile (dataurl, filename) {let arr = dataurl.split(',') let mime = arr[0].match(/:(.*?) ; / [1]); if(! Filename = date.parse (new Date()) + '.jpg'; } 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, {type:mime}); }, //base64 to blob dataURItoBlob(base64Data) {var byteString; if(base64Data.split(',')[0].indexOf('base64') >= 0) byteString = atob(base64Data.split(',')[1]); else{ byteString = unescape(base64Data.split(',')[1]); } var mimeString = base64Data.split(',')[0].split(':')[1].split('; ') [0]; var ia = new Uint8Array(byteString.length); for(var i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } var blob = new Blob([ia], { type: mimeString }); return blob; } let blob = this.$api.dataurlTofile (this.base64Data); formData.set("file", blob); // Finally upload formData to your Ajax interfaceCopy the code
I used the method of converting to file. At the beginning, WHEN I used bloB to upload, I always reported 500. The background said that since there was no file name, I should use the first method again