Question

i wrote a project that work well with upload and download objects to/from Google Cloud Storage. I'm able to retrieve the content, the stream, the metadata, but when i get the 'mediaLink' of an object and paste it to the browser, i got this error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

the format of mediaLink URL is shown here:

https://content.googleapis.com/storage/v1/b/bucketname/o/folder%2Finsidefolder%2Fexample.txt

I'm authenticated in my website by the OAuth 2.0 flow, and all the objects uploaded on GCS are with a custom AccessControlList which i decided to set into "allAuthenticatedUsers" in order to give access only to user that are authenticated with my website.

Could anyone help me to solve this issue? Thank you so much

Was it helpful?

Solution

The media link is not inherently authorized. You need to authorize a download using the media link in the same way you'd authorize any other request: by including an appropriate "Authorization" header.

Without providing read permission to "AllUsers", the media link will not work in a web browser.

Also, "AllAuthenticatedUsers" does not mean users that are authenticated with your website. It means "anybody with any Google account."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top