[PR #497] [MERGED] Fix nodeJS file upload (issue #346) #660

Closed
opened 2026-03-03 12:31:03 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fsouza/fake-gcs-server/pull/497
Author: @dpoetzsch
Created: 5/18/2021
Status: Merged
Merged: 5/19/2021
Merged by: @fsouza

Base: mainHead: iss346


📝 Commits (2)

📊 Changes

2 files changed (+17 additions, -6 deletions)

View changed files

📝 fakestorage/upload.go (+13 -6)
📝 fakestorage/upload_test.go (+4 -0)

📄 Description

As https://github.com/fsouza/fake-gcs-server/issues/346 states, there is a bug when uploading files with the nodeJS client lib.

I debugged it and the problem is, that nodeJS sends Content-Range: bytes 0-*/* (see https://github.com/googleapis/gcs-resumable-upload/blob/master/src/index.ts#L456).

I could not really find a good documentation on the exact semantics but from observing the client lib I guess it means "start and end upload stream with all the data I provide you". I adjusted the code accordingly and added a test case. I also checked that the following node example works fine:

async function saveFile() {
  // [START storage_list_buckets]
  // Imports the Google Cloud client library
  const { Storage } = require("@google-cloud/storage");

  // Creates a client
  const storage = new Storage({
    apiEndpoint: "http://localhost:8080",
    projectId: "test",
  });

  const bucket = await storage.createBucket("testbucket");
  const file = new File(bucket, "test.txt");
  await file.save("abc", { contentType: "text/plain" });
  // [END storage_list_buckets]
}

saveFile().catch((err) => {
  console.error(err);
  process.exit(1);
});

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fsouza/fake-gcs-server/pull/497 **Author:** [@dpoetzsch](https://github.com/dpoetzsch) **Created:** 5/18/2021 **Status:** ✅ Merged **Merged:** 5/19/2021 **Merged by:** [@fsouza](https://github.com/fsouza) **Base:** `main` ← **Head:** `iss346` --- ### 📝 Commits (2) - [`d1a2e72`](https://github.com/fsouza/fake-gcs-server/commit/d1a2e724f35ab84af5eeb91f7149170147f2c7f4) fixed https://github.com/fsouza/fake-gcs-server/issues/346 - [`b606b19`](https://github.com/fsouza/fake-gcs-server/commit/b606b19f24ac153d8c02fef79fddb1d3ab7733b9) simplified ### 📊 Changes **2 files changed** (+17 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `fakestorage/upload.go` (+13 -6) 📝 `fakestorage/upload_test.go` (+4 -0) </details> ### 📄 Description As https://github.com/fsouza/fake-gcs-server/issues/346 states, there is a bug when uploading files with the nodeJS client lib. I debugged it and the problem is, that nodeJS sends `Content-Range: bytes 0-*/*` (see https://github.com/googleapis/gcs-resumable-upload/blob/master/src/index.ts#L456). I could not really find a good documentation on the exact semantics but from observing the client lib I guess it means "start and end upload stream with all the data I provide you". I adjusted the code accordingly and added a test case. I also checked that the following node example works fine: ```javascript async function saveFile() { // [START storage_list_buckets] // Imports the Google Cloud client library const { Storage } = require("@google-cloud/storage"); // Creates a client const storage = new Storage({ apiEndpoint: "http://localhost:8080", projectId: "test", }); const bucket = await storage.createBucket("testbucket"); const file = new File(bucket, "test.txt"); await file.save("abc", { contentType: "text/plain" }); // [END storage_list_buckets] } saveFile().catch((err) => { console.error(err); process.exit(1); }); ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 12:31:03 +03:00
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#660
No description provided.