@@ -83,25 +83,32 @@ If you don't have a bucket already, follow the steps of the [Creating a Bucket g
83
83
See the [ gcloud-node Storage API documentation] [ gcloud-storage-docs ] to learn how to connect to Cloud Storage using this library.
84
84
85
85
``` js
86
+ var fs = require (' fs' );
86
87
var gcloud = require (' gcloud' );
87
- var bucket ;
88
+ var storage ;
88
89
89
90
// From Google Compute Engine:
90
- bucket = gcloud .storage .bucket ({
91
- projectId: ' my-project' ,
92
- bucketName: ' my-bucket'
91
+ storage = gcloud .storage ({
92
+ projectId: ' my-project'
93
93
});
94
94
95
95
// Or from elsewhere:
96
- bucket = gcloud .storage .bucket ({
97
- projectId: ' my-project' ,
96
+ storage = gcloud .storage ({
98
97
keyFilename: ' /path/to/keyfile.json' ,
99
- bucketName : ' my-bucket '
98
+ projectId : ' my-project '
100
99
});
101
100
102
- bucket .write (' demo.txt' , ' Hello World' , function (err ) {
103
- console .log (err || ' Created demo.txt' );
104
- });
101
+ // Create a new bucket.
102
+ storage .createBucket (' my-new-bucket' , function (err , bucket ) {});
103
+
104
+ // Reference an existing bucket.
105
+ var bucket = storage .bucket (' my-bucket' );
106
+
107
+ // Upload a local file to a new file to be created in your bucket.
108
+ fs .createReadStream (' /local/file.txt' ).pipe (bucket .file (' file.txt' ));
109
+
110
+ // Download a remote file to a new local file.
111
+ bucket .file (' photo.jpg' ).pipe (fs .createWriteStream (' /local/photo.jpg' ));
105
112
```
106
113
107
114
## Google Cloud Pub/Sub (Alpha)
0 commit comments