J Query
J Query

Reputation: 305

How to view Google API cloud storage files in browser

I am working with Google API storage to save my uploaded files in cloud.

I have uploaded a pdf file into that storage and it returns a self link for that file, as follows, https://www.googleapis.com/storage/v1/b/mystorage/o/file.pdf

When I am trying to enter this link in browser, it shows the following json object,

    {
     "kind": "storage#object",
     "id": "myStorage/myFile.pdf/2152448693558409",
     "selfLink": "https://www.googleapis.com/storage/v1/b/myStorage/o/myFile.pdf",
     "name": "myFile.pdf",
     "bucket": "myStorage",
     "generation": "2152448693558409",
     "metageneration": "1",
     "timeCreated": "2018-04-23T12:35:35.579Z",
     "updated": "2018-04-23T12:35:35.579Z",
     "storageClass": "REGIONAL",
     "timeStorageClassUpdated": "2018-04-23T12:35:35.579Z",
     "size": "3028",
     "md5Hash": "EF0GjR1EyvYYbMKh44wqla==",
     "mediaLink": "https://www.googleapis.com/download/storage/v1/b/myStorage/o/myFile.pdf?generation=2152448693558409&alt=media",
     "crc32c": "uSlJNw==",
     "etag": "COO6irK00NoCEAE="
    }

I copied that media link and pasted in browser, but the pdf file is downloaded instead of viewing that in browser.

Can someone please assist in this, how to view the files?

Upvotes: 1

Views: 4472

Answers (1)

komarkovich
komarkovich

Reputation: 2319

In order to view your file in a browser you have to either:

  1. Make file public and access it with a link: https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]
  2. Add READER role, for your Google account, to the file and access it with a link: https://storage.cloud.google.com/[BUCKET_NAME]/[OBJECT_NAME]

Upvotes: 1

Related Questions