Giter Club home page Giter Club logo

Comments (15)

elharo avatar elharo commented on July 28, 2024

Can you reproduce this without scala?

from java-storage.

soujiro32167 avatar soujiro32167 commented on July 28, 2024

With a single file names 1 1

import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

import java.nio.file.Path;

public class Yava {
  public static void main(String[] args) {
    Storage storage = StorageOptions.getDefaultInstance().getService();
    storage.list("eli-test").iterateAll().forEach(blob -> blob.downloadTo(Path.of("target", blob.getName())));
  }
}
Exception in thread "main" com.google.cloud.RetryHelper$RetryHelperException: com.google.cloud.storage.StorageException: 404 Not Found
No such object: eli-test/1+1
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
	at com.google.cloud.storage.Blob.downloadTo(Blob.java:233)
	at com.google.cloud.storage.Blob.downloadTo(Blob.java:217)
	at com.google.cloud.storage.Blob.downloadTo(Blob.java:260)
	at Yava.lambda$main$0(Yava.java:9)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at Yava.main(Yava.java:9)
Caused by: com.google.cloud.storage.StorageException: 404 Not Found
No such object: eli-test/1+1
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:229)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:675)
	at com.google.cloud.storage.Blob$2.run(Blob.java:238)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
	... 6 more
Caused by: com.google.api.client.http.HttpResponseException: 404 Not Found
No such object: eli-test/1+1
	at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1113)
	at com.google.api.client.googleapis.media.MediaHttpDownloader.executeCurrentRequest(MediaHttpDownloader.java:255)
	at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:185)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAndDownloadTo(AbstractGoogleClientRequest.java:685)
	at com.google.api.services.storage.Storage$Objects$Get.executeMediaAndDownloadTo(Storage.java:6996)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:671)
	... 11 more

from java-storage.

elharo avatar elharo commented on July 28, 2024

Do you have a pom.xml or build.gradle for this?

from java-storage.

soujiro32167 avatar soujiro32167 commented on July 28, 2024

I have sbt: "com.google.cloud" % "google-cloud-storage" % "1.103.1"

from java-storage.

soujiro32167 avatar soujiro32167 commented on July 28, 2024

the only thing needed is the gcloud storage dependency

from java-storage.

athakor avatar athakor commented on July 28, 2024

@soujiro32167 Thanks for pointing out this bug, but it's related to google-http-java-client.

FYI, A string of characters that do not need to be encoded when used in URI query strings, as
specified in RFC 3986. Note that some of these characters do need to be escaped when used in
other parts of the URI and space is one of them which needs to be escape.

you can check list of rules for an encoding a string which is parts of the URI.

Rules :
https://github.com/googleapis/google-http-java-client/blob/master/google-http-client/src/main/java/com/google/api/client/util/escape/PercentEscaper.java#L32

Also look at the below links which replacse the space with {'+'}

https://github.com/googleapis/google-http-java-client/blob/master/google-http-client/src/main/java/com/google/api/client/util/escape/PercentEscaper.java#L218

https://github.com/googleapis/google-http-java-client/blob/master/google-http-client/src/main/java/com/google/api/client/util/escape/PercentEscaper.java#L93

from java-storage.

elharo avatar elharo commented on July 28, 2024

The problem is not that the space is not being encoded. It's that it's being encoded incorrectly as a plus sign. This is wrong. The plus sign is the plus sign. It is not a space and does not represent one in URLs. This is a common confusion between URL encoding and application-x-www-formurl-encoding. The latter only applies in HTML forms.

This is complicated because there's a lot of broken code out there that does not follow the spec. To make matters worse, some of the GCS code is trying to be bug-for-bug compatible with other non-Google code.

from java-storage.

dmitry-fa avatar dmitry-fa commented on July 28, 2024

I thinks this is a duplicate of #57
it's still reproducible with google-http-client 1.34.1

Workaround to add this dependency:

        <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client</artifactId>
            <version>1.33.0</version>
        </dependency>

from java-storage.

athakor avatar athakor commented on July 28, 2024

The problem is not that the space is not being encoded. It's that it's being encoded incorrectly as a plus sign. This is wrong. The plus sign is the plus sign. It is not a space and does not represent one in URLs. This is a common confusion between URL encoding and application-x-www-formurl-encoding. The latter only applies in HTML forms.

This is complicated because there's a lot of broken code out there that does not follow the spec. To make matters worse, some of the GCS code is trying to be bug-for-bug compatible with other non-Google code.

Correct. Spaces should be encoded as %20 instead of a plus sign.

from java-storage.

elharo avatar elharo commented on July 28, 2024

The bug is in com.google.api.client.http.UriTemplate#expand or something it calls. This is where the + sign is incorrectly introduced.

from java-storage.

dmitry-fa avatar dmitry-fa commented on July 28, 2024

I built google-http-client 1.34.2-SNAPSHOT, the problem with spaces is gone!

from java-storage.

elharo avatar elharo commented on July 28, 2024

FYI if you import com.google.cloud:libraries-bom:4.1.0 or later the bug is fixed. We still need to release a version of the google-cloud-storage artifact that updates its dependencies.

  <dependencyManagement>
	 <dependencies>
	  <dependency>
	    <groupId>com.google.cloud</groupId>
	    <artifactId>libraries-bom</artifactId>
	    <version>4.1.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>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

from java-storage.

frankyn avatar frankyn commented on July 28, 2024

@soujiro32167 could you try using the latest release:
https://search.maven.org/artifact/com.google.cloud/google-cloud-storage-parent/1.104.0/pom

Thank you for your patience folks.

from java-storage.

frankyn avatar frankyn commented on July 28, 2024

Verified the latest version has resolved the issue (GoogleCloudPlatform/java-docs-samples#2064). Closing issue, please reopen if the issue persists.

from java-storage.

soujiro32167 avatar soujiro32167 commented on July 28, 2024

@frankyn thanks! I'll try it out

from java-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.