[GH-ISSUE #1556] Calling bucket.file.exists always returns false #203

Closed
opened 2026-03-03 12:09:07 +03:00 by kerem · 5 comments
Owner

Originally created by @VanPaitin on GitHub (Apr 11, 2024).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1556

import { Storage } from '@google-cloud/storage';

const storage = new Storage();
const apiBucket = storage.bucket('api-video-song-renderer-bucket-test');
apiBucket.file(`shakaraSTART`).save("Hello world", {
  public: true
});

Running the code above correctly creates a file in the bucket. When I check the logs, I see it makes a call to
POST /upload/storage/v1/b/api-video-song-renderer-bucket-test/o?name=shakaraSTART&uploadType=resumable&predefinedAcl=publicRead.

However, when I try to check with:

apiBucket.file('shakaraSTART').exists().then(exists => {
  expect(exists).toBe(true);
});

I am always getting a false value meaning the file doesn't exist when it infact exists. I checked the logs and it was making calls to
GET /b/api-video-song-renderer-bucket-test/o/shakaraSTART

Observe that it doesn't prepend the endpoint with /storage/v1. This is probably why I am getting a 404 error.

  1. Is there a work around for this?
  2. Is this a bug and will it be fixed?
  3. What may I be getting wrong?
Originally created by @VanPaitin on GitHub (Apr 11, 2024). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1556 ```node import { Storage } from '@google-cloud/storage'; const storage = new Storage(); const apiBucket = storage.bucket('api-video-song-renderer-bucket-test'); apiBucket.file(`shakaraSTART`).save("Hello world", { public: true }); ``` Running the code above correctly creates a file in the bucket. When I check the logs, I see it makes a call to `POST /upload/storage/v1/b/api-video-song-renderer-bucket-test/o?name=shakaraSTART&uploadType=resumable&predefinedAcl=publicRead`. However, when I try to check with: ```node apiBucket.file('shakaraSTART').exists().then(exists => { expect(exists).toBe(true); }); ``` I am always getting a false value meaning the file doesn't exist when it infact exists. I checked the logs and it was making calls to `GET /b/api-video-song-renderer-bucket-test/o/shakaraSTART` Observe that it doesn't prepend the endpoint with `/storage/v1`. This is probably why I am getting a 404 error. 1. Is there a work around for this? 2. Is this a bug and will it be fixed? 3. What may I be getting wrong?
kerem closed this issue 2026-03-03 12:09:08 +03:00
Author
Owner

@fsouza commented on GitHub (Apr 15, 2024):

How did you configure the node client to talk to fake-gcs-server?

<!-- gh-comment-id:2054615965 --> @fsouza commented on GitHub (Apr 15, 2024): How did you configure the node client to talk to fake-gcs-server?
Author
Owner

@VanPaitin commented on GitHub (Apr 15, 2024):

Thanks @fsouza for your reply. I am configuring the client simply by setting the env variable: STORAGE_EMULATOR_HOST='http://localhost:4443'

<!-- gh-comment-id:2055383236 --> @VanPaitin commented on GitHub (Apr 15, 2024): Thanks @fsouza for your reply. I am configuring the client simply by setting the env variable: STORAGE_EMULATOR_HOST='http://localhost:4443'
Author
Owner

@VanPaitin commented on GitHub (Apr 29, 2024):

@fsouza, should I expect a solution?

<!-- gh-comment-id:2083668050 --> @VanPaitin commented on GitHub (Apr 29, 2024): @fsouza, should I expect a solution?
Author
Owner

@fsouza commented on GitHub (Apr 30, 2024):

Can you provide exact steps for reproducing the issue?

I just tried to reproduce with the example in the repo and couldn't: https://github.com/fsouza/fake-gcs-server/pull/1585

If the client is not sending the correct request to the server, I assume the client is misconfigured.

<!-- gh-comment-id:2084413212 --> @fsouza commented on GitHub (Apr 30, 2024): Can you provide exact steps for reproducing the issue? I just tried to reproduce with the example in the repo and couldn't: https://github.com/fsouza/fake-gcs-server/pull/1585 If the client is not sending the correct request to the server, I assume the client is misconfigured.
Author
Owner

@fsouza commented on GitHub (May 2, 2024):

Merged #1585, see that for an example on how to setup the Node client in a way where that method works.

<!-- gh-comment-id:2089457664 --> @fsouza commented on GitHub (May 2, 2024): Merged #1585, see that for an example on how to setup the Node client in a way where that method works.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#203
No description provided.