base64toBlob函数
base64toBlob (base64Data, contentType) {contentType = contentType || \'\'var sliceSize = 1024var byteCharacters = atob(base64Data)var bytesLength = byteCharacters.lengthvar slicesCount = Math.ceil(bytesLength / sliceSize)var byteArrays = new Array(slicesCount)for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {var begin = sliceIndex * sliceSizevar end = Math.min(begin + sliceSize, bytesLength)var bytes = new Array(end - begin)for (var offset = begin, i = 0; offset < end; ++i, ++offset) {bytes[i] = byteCharacters[offset].charCodeAt(0)}byteArrays[sliceIndex] = new Uint8Array(bytes)}return new Blob(byteArrays, { type: contentType })}
单文件上传
let base64file = this.webOfficeObj.obj.File2Base64Text(data.path)let myfff = this.base64toBlob(base64file)let formData = new FormData()formData.append(\'file\', myfff, this.webOfficeObj.FileName)axios({method: \'post\',url: url || this.webOfficeObj.WebUrl,data: formData,headers: {Accept: \'application/json, text/plain, */*\',Authorization: \'bearer \' + this.$http.getAccessToken(),\'Content-Type\': \'multipart/form-data\'}}).then(({data}) => {if (data && data.code === 0) {this.$emit(\'upload-success\', data)} else {this.$message({message: data.msg,type: \'error\',duration: 1500})}}).catch(() => {this.$message.error(\'文件上传失败\')})
多文件上传
let formData = new FormData()data.fileList.forEach(item => {let base64file = this.webOfficeObj.obj.File2Base64Text(item.path)let myfff = this.base64toBlob(base64file)formData.append(\'file[]\', myfff, item.fileName)})axios({method: \'post\',url: url || this.webOfficeObj.WebUrl,data: formData,headers: {Accept: \'application/json, text/plain, */*\',Authorization: \'bearer \' + this.$http.getAccessToken(),\'Content-Type\': \'multipart/form-data\'}}).then(({data}) => {if (data && data.code === 0) {this.$emit(\'upload-success\', data)} else {this.$message({message: data.msg,type: \'error\',duration: 1500})}}).catch(() => {this.$message.error(\'文件上传失败\')})