How to generate signed URL of file in google cloud storage using only OAuth 2.0 bearer token and bucket name? (PHP code)


King Mark

I have tried the code below and it works fine. However, it would be ideal if I could just use the OAuth 2.0 access token and bucket name to get the signed URL.

I have tried many things but still nowhere.

function getSignedURL($file, $expiryMinutes = 30)
{

    $privateKeyFileContent = '{
     // service account generated key
    }';

    $storage = new StorageClient([
        'keyFile' => json_decode($privateKeyFileContent, true)
    ]);
    $bucket = $storage->bucket("as-portal");
    $object = $bucket->object($file);
    $url = $object->signedUrl(
    # This URL is valid for 15 minutes
        new \DateTime("$expiryMinutes min"),
        [
            'version' => 'v4',
        ]
    );
}

Any help would be greatly appreciated!

Bisolato

Currently, all available methods for signing URLs require the service account's private key, as described in Options for generating signed URLs . Therefore, it is not possible to sign the URL locally without the private key of the service account.

However, you can sign remotely as described in this example . I recommend having the App Engine service sign the url for you, as described in the Signing Strings with Google Cloud Tools section of the documentation .

Related


Upload file to Google Cloud Storage signed URL using Python

Raj Chaudhary Can someone help me with the code, preferably using the Requests library to upload a file to a Google Cloud Storage signed URL in Python? Lundin Custer You can check out this sample code on Github . It shows a portable way to achieve this using P

Upload file to Google Cloud Storage signed URL using Python

Raj Chaudhary Can someone help me with the code, preferably using the Requests library to upload a file to a Google Cloud Storage signed URL in Python? Lundin Custer You can check out this sample code on Github . It shows a portable way to achieve this using P

Upload file to Google Cloud Storage signed URL using Python

Raj Chaudhary Can someone help me with the code, preferably using the Requests library to upload a file to a Google Cloud Storage signed URL in Python? Lundin Custer You can check out this sample code on Github . It shows a portable way to achieve this using P

upload file to google cloud storage with signed url using ajax

David I try to upload a file to my Google Cloud Storage using signed url. I have set CORS parameters on my bucket using gsutil Browser sends ajax request to Django backend to get signed url Django backend makes request to GCS to create signed url The signed ur

Upload file to Google Cloud Storage signed URL using Python

Raj Chaudhary Can someone help me with the code, preferably using the Requests library to upload a file to a Google Cloud Storage signed URL in Python? Lundin Custer You can check out this sample code on Github . It shows a portable way to achieve this using P

Upload file to Google Cloud Storage signed URL using Python

Raj Chaudhary Can someone help me with the code, preferably using the Requests library to upload a file to a Google Cloud Storage signed URL in Python? Lundin Custer You can check out this sample code on Github . It shows a portable way to achieve this using P

How to upload file to google cloud storage bucket using signedUrl

Ghizlane Lotfi I am developing an Angular app to display the contents of a Google cloud storage bucket. In the back I am using Google Cloud functions in nodeJS As they mentioned in the documentation to upload the file, I created a function to generate the sign

How to upload file to google cloud storage bucket using signedUrl

Ghizlane Lotfi I am developing an Angular app to display the contents of a Google cloud storage bucket. In the back I am using Google Cloud functions in nodeJS As they mentioned in the documentation to upload the file, I created a function to generate the sign