Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/app/services/photo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ export class PhotoService {

base64Data = file.data;
} else {
// Fetch the photo, read as a blob, then convert to base64 format
const response = await fetch(photo.webPath!);
const blob = await response.blob();

base64Data = (await this.convertBlobToBase64(blob)) as string;
base64Data = await this.base64FromPath(photo.webPath!);
}

// Write the file to the data directory
Expand Down Expand Up @@ -91,12 +87,18 @@ export class PhotoService {
}
}

private convertBlobToBase64(blob: Blob) {
private async base64FromPath(path: string): Promise<string> {
const response = await fetch(path);
const blob = await response.blob();
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
if (typeof reader.result === 'string') {
resolve(reader.result);
} else {
reject('method did not return a string');
}
};
reader.readAsDataURL(blob);
});
Expand Down