0

I need to get the base64 data from photos sotred in a google photo album i own.

I'm accessing the google photo album throught the google photo api. I'm selecting a photo (using either the baseUrl either the productUrl). I'm "sending" this photo to a canvas HTMLElement. When i'm using the toDataUrl function, i'm facing an issue related to CORS : ERROR DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

I try to add the crossorigin property in the img tag but the result is not better... crossorigin="anonymous" don't allow me to display my photo... crossorigin='use-credentials" has the same result, but in this case, i don't know how to define the credentials...

component.html : 
      <div *ngIf="photos" class="divPhotos">
      <img *ngFor="let photo of photos" class="photo" [src]="photo.baseUrl" height="200" [alt]="photo.filename" (click)="selectPhoto(photo)" [id]="photo.filename">
      <canvas id="canvas"></canvas>
      </div>

component.ts : 
        const  img = document.getElementById(photo.filename);
        const  canvas = document.getElementById('canvas');

        // @ts-ignore
        const ctx = canvas.getContext('2d');
        // @ts-ignore
        ctx.drawImage(img, 0, 0);
        // @ts-ignore
        dataURL = canvas.toDataURL();

Is there a way to get the base64 data from a google photo?

  • If the server doesn't allow cross-origin access of their resources by sending the correct `Access-Control-Allow-Origin`, nope. (assuming you are not in a position to change google-photo's servers configuration) – Kaiido Apr 09 '19 at 07:57
  • to bad...actually the googlePhoto APi is usefull to manage albums and send photos... But not really to access them... Is there an another way to succeed in getting base64 data from a google photo? – user11271108 Apr 09 '19 at 11:05

0 Answers0