public URL generateV4GetObjectSignedUrl ( String bucketName , String objectName ) throws StorageException { // [START storage_generate_signed_url_v4] // Instantiate a Google Cloud Storage client Storage storage = StorageOptions . getDefaultInstance ( ) . getService ( ) ; // The name of a bucket, e.g. "my-bucket" // String bucketName = "my-bucket"; // The name of an object, e.g. "my-object" // String objectName = "my-object"; // Define resource BlobInfo blobinfo = BlobInfo . newBuilder ( BlobId . of ( bucketName , objectName ) ) . build ( ) ; // Generate Signed URL URL url = storage . signUrl ( blobinfo , 15 , TimeUnit . MINUTES , Storage . SignUrlOption . withV4Signature ( ) ) ; System . out . println ( "Generated GET signed URL:" ) ; System . out . println ( url ) ; System . out . println ( "You can use this URL with any user agent, for example:" ) ; System . out . println ( "curl '" + url + "'" ) ; // [END storage_generate_signed_url_v4] return url ; }
Example of how to generate a GET V4 Signed URL