forked from trent_larson/crowd-funder-for-time-pwa
fix image shared with web share
This commit is contained in:
@@ -566,14 +566,27 @@ async function getNotificationCount() {
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function blobToBase64String(blob) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result); // potential problem if it returns an ArrayBuffer?
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
|
||||
// Store the image blob and go immediate to a page to upload it.
|
||||
// @param photo - image Blob to store for later retrieval after redirect
|
||||
async function savePhoto(photo) {
|
||||
try {
|
||||
const photoBase64 = await blobToBase64String(photo);
|
||||
const db = await openIndexedDB("TimeSafari");
|
||||
const transaction = db.transaction("temp", "readwrite");
|
||||
const store = transaction.objectStore("temp");
|
||||
await updateRecord(store, { id: "shared-photo", blob: photo });
|
||||
await updateRecord(store, {
|
||||
id: "shared-photo-base64",
|
||||
blobB64: photoBase64,
|
||||
});
|
||||
transaction.oncomplete = () => db.close();
|
||||
} catch (error) {
|
||||
console.error("safari-notifications logMessage IndexedDB error", error);
|
||||
|
||||
Reference in New Issue
Block a user