Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file download to node example #530

Merged
merged 6 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/node/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
storage:
image: fsouza/fake-gcs-server
build: ../../
ports:
- 8080:8080
volumes:
- ../data:/data
command: ["-scheme", "http", "-port", "8080", "-external-url", "http://localhost:8080", "-backend", "memory"]
13 changes: 11 additions & 2 deletions examples/node/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async function listBuckets() {
async function run() {
// [START storage_list_buckets]
// Imports the Google Cloud client library
const { Storage } = require("@google-cloud/storage");
Expand All @@ -16,9 +16,18 @@ async function listBuckets() {
console.log(bucket.id);
});
// [END storage_list_buckets]

const [content] = await storage.bucket('sample-bucket')
.file('some_file.txt')
.download({
// validation: false // FIXME: needed when x-goog-hash header isn't present on the response
});
fsouza marked this conversation as resolved.
Show resolved Hide resolved
console.log("Contents:")
console.log(content.toString())
}

listBuckets().catch((err) => {

run().catch((err) => {
console.error(err);
process.exit(1);
});
1 change: 1 addition & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"run": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
Expand Down
1 change: 1 addition & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Length", strconv.Itoa(len(content)))
w.Header().Set(contentTypeHeader, obj.ContentType)
w.Header().Set("X-Goog-Generation", strconv.FormatInt(obj.Generation, 10))
w.Header().Set("X-Goog-Hash", fmt.Sprintf("crc32c=%s,md5=%s", obj.Crc32c, obj.Md5Hash))
w.Header().Set("Last-Modified", obj.Updated.Format(http.TimeFormat))
if obj.ContentEncoding != "" {
w.Header().Set("Content-Encoding", obj.ContentEncoding)
Expand Down