Skip to content

content: your-first-app, readAsBase64 function has type error in Angular #2986

Closed
@nandanchandra

Description

@nandanchandra

URL

https://github.com/ionic-team/ionic-docs/blob/main/docs/angular/your-first-app/5-adding-mobile.md

Issue Description

What is missing or inaccurate about the content on this page?

Missing : fileName
Description : path: photo.path generating error as Type 'string | undefined' is not assignable to type 'string'.

Modified Code :

private async readAsBase64(photo: Photo) {
  // "hybrid" will detect Cordova or Capacitor
  const fileName = new Date().getTime() + '.jpeg';
  
  if (this.platform.is('hybrid')) {
    // Read the file into base64 format
    const file = await Filesystem.readFile({
      path: fileName
    });

    return 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();

      return await this.convertBlobToBase64(blob) as string;
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentIssues related to the contents of the documentation website

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions