2

I tried to get blob from Google Photos media items. However, when I tried to fetch from baseUrl, I got error cause by CORS policy.

const blob = fetch(
    file.baseUrl + "=w" + file.mediaMetadata.width + "-h" + file.mediaMetadata,
    {
      headers: {
        Authorization: "Bearer " + authToken
      }
    }
  ).then(res => res.blob());

And when I tried to use, gapi request, I got error 404.

const blob = gapi.client.request({
      path: file.baseUrl + "=w" + file.mediaMetadata.width + "-h" + file.mediaMetadata
    })
    .then(res => res.blob());

Can someone point me out regarding this problem? Or give me some help to get blob from GooglePhotos.

Thanks.

drs
  • 54
  • 3

1 Answers1

1

It looks like the Google Photos endpoints do not support CORS access to pixel data.

https://issuetracker.google.com/issues/118662029

Again, it is fine to use curl or <img> tags to display the pixels. You just cannot get the data in the client JS until CORS access is added.

I had also written up a separate SO post on the same topic.

Another solution, if you can modify your server, is to provide your own endpoint that will copy the file data from GPhotos to the server and pipe the results up to the client.

Daniel Wexler
  • 131
  • 1
  • 7