feat:完成头像上传的功能

This commit is contained in:
YunaiV
2025-04-22 09:19:19 +08:00
parent fd98752073
commit 1dbbc547fb
14 changed files with 839 additions and 22 deletions

View File

@@ -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