0

Getting Storage Exception while connection with GCS !!

<dependencies>
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-storage</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>30.0-jre</version>
    </dependency>
</dependencies>

enter image description here

Anil kumar
  • 21
  • 6
  • 1
    You may want to look in [this](https://stackoverflow.com/questions/61597801/java-lang-nosuchmethoderror-com-google-common-io-bytestreams-exhaustljava-io-i) stack post. Issue is only encountered when running the class in IntelliJ as also mentioned in this [link](https://stackoverflow.com/questions/68564991/accessing-gcs-with-json-key-in-java-and-got-method-threw-com-google-cloud-stora). – Catherine O Jan 14 '22 at 07:05

1 Answers1

1

Did some changes in the code and it works

StorageOptions options = StorageOptions.newBuilder()
                    .setProjectId(PROJECT_ID)
                    .setCredentials(GoogleCredentials.fromStream(new FileInputStream(PATH_TO_JSON_KEY))).build();
            Storage storage = options.getService();
            byte[] bytes = storage.readAllBytes(BlobId.of(BUCKET_NAME, OBJECT_NAME));

use storage.readAllBytes() instead of storage.get()

My Pom

     <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.google.cloud</groupId>
                    <artifactId>libraries-bom</artifactId>
                    <version>24.2.0</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>com.google.cloud</groupId>
                <artifactId>google-cloud-storage</artifactId>
            </dependency>

            <dependency>
                <groupId>com.google.apis</groupId>
                <artifactId>google-api-services-storage</artifactId>
                <version>v1-rev20190129-1.26.0</version>
            </dependency>

            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </dependency>
        </dependencies>

use v1-rev20190129-1.26.0 for google-api-services-storage because higher version is not compatible with cloud-storage 2.2.3v

Anil kumar
  • 21
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). –  Jan 14 '22 at 22:45