complete mobile image upload

This commit is contained in:
2024-12-18 01:07:10 +08:00
parent b11641f62e
commit 68a8e3e5c4
26 changed files with 455 additions and 83 deletions

View File

@@ -6,8 +6,7 @@ export const localforageStorageAdapter = {
await localforage.setItem(key, value);
},
async get(key: string) {
const res: any = await localforage.getItem(key);
return res ? JSON.parse(res) : null;
return await localforage.getItem(key);
},
async remove(key: any) {
await localforage.removeItem(key);

View File

@@ -0,0 +1,22 @@
export async function blobToBase64(blobUrl: string): Promise<string> {
try {
const response = await fetch(blobUrl);
const blob = await response.blob();
const reader = new FileReader();
return new Promise<string>((resolve, reject) => {
reader.onload = function () {
// 直接使用 reader.result包含 MIME 类型前缀
const base64StringWithPrefix = reader.result!.toString();
resolve(base64StringWithPrefix);
};
reader.onerror = function () {
reject("File could not be read");
};
// 读取 Blob 文件到 Data URL 格式
reader.readAsDataURL(blob);
});
} catch (error) {
throw new Error("Error fetching blob from URL: " + error);
}
}