feat:完成头像上传的功能
This commit is contained in:
@@ -96,6 +96,25 @@ export function downloadFileFromBlobPart({
|
||||
triggerDownload(url, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: base64 to blob
|
||||
*/
|
||||
export function dataURLtoBlob(base64Buf: string): Blob {
|
||||
const arr = base64Buf.split(',');
|
||||
const typeItem = arr[0];
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const mime = typeItem!.match(/:(.*?);/)![1];
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const bstr = window.atob(arr[1]!);
|
||||
let n = bstr.length;
|
||||
const u8arr = new Uint8Array(n);
|
||||
while (n--) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
u8arr[n] = bstr.codePointAt(n)!;
|
||||
}
|
||||
return new Blob([u8arr], { type: mime });
|
||||
}
|
||||
|
||||
/**
|
||||
* img url to base64
|
||||
* @param url
|
||||
|
||||
Reference in New Issue
Block a user