|
1 | | -<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/> |
| 1 | +Samples for the [Google Cloud Storage Node.js Client][client] have moved to |
| 2 | +[github.com/googleapis/nodejs-storage: samples/][samples]. |
2 | 3 |
|
3 | | -# Google Cloud Storage Node.js Samples |
4 | | - |
5 | | -[]() |
6 | | - |
7 | | -[Cloud Storage](https://cloud.google.com/storage/docs) allows world-wide storage and retrieval of any amount of data at any time. You can use Google Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download. |
8 | | - |
9 | | -## Table of Contents |
10 | | - |
11 | | -* [Setup](#setup) |
12 | | -* [Samples](#samples) |
13 | | - * [ACL (Access Control Lists)](#acl-access-control-lists) |
14 | | - * [Buckets](#buckets) |
15 | | - * [Encryption](#encryption) |
16 | | - * [Files](#files) |
17 | | - * [Storage Transfer API](#storage-transfer-api) |
18 | | - * [Requester Pays samples](#requester-pays-samples) |
19 | | -* [Running the tests](#running-the-tests) |
20 | | - |
21 | | -## Setup |
22 | | - |
23 | | -1. Read [Prerequisites][prereq] and [How to run a sample][run] first. |
24 | | -1. Install dependencies: |
25 | | - |
26 | | - With **npm**: |
27 | | - |
28 | | - npm install |
29 | | - |
30 | | - With **yarn**: |
31 | | - |
32 | | - yarn install |
33 | | - |
34 | | -[prereq]: ../README.md#prerequisites |
35 | | -[run]: ../README.md#how-to-run-a-sample |
36 | | - |
37 | | -## Samples |
38 | | - |
39 | | -### ACL (Access Control Lists) |
40 | | - |
41 | | -View the [documentation][acl_0_docs] or the [source code][acl_0_code]. |
42 | | - |
43 | | -__Usage:__ `node acl.js --help` |
44 | | - |
45 | | -``` |
46 | | -Commands: |
47 | | - print-bucket-acl <bucketName> Prints the ACL for a bucket. |
48 | | - print-bucket-acl-for-user <bucketName> <userEmail> Prints a user's ACL for a bucket. |
49 | | - add-bucket-owner <bucketName> <userEmail> Adds a user as an owner of a bucket. |
50 | | - remove-bucket-owner <bucketName> <userEmail> Removes a user from the ACL of a bucket. |
51 | | - add-bucket-default-owner <bucketName> <userEmail> Adds a user as an owner in the default ACL of a bucket. |
52 | | - remove-bucket-default-owner <bucketName> <userEmail> Removes a user from the default ACL of a bucket. |
53 | | - print-file-acl <bucketName> <fileName> Prints the ACL for a file. |
54 | | - print-file-acl-for-user <bucketName> <fileName> <userEmail> Prints a user's ACL for a file. |
55 | | - add-file-owner <bucketName> <fileName> <userEmail> Adds a user as an owner of a file. |
56 | | - remove-file-owner <bucketName> <fileName> <userEmail> Removes a user from the ACL of a file. |
57 | | -
|
58 | | -Options: |
59 | | - --help Show help [boolean] |
60 | | -
|
61 | | -Examples: |
62 | | - node acl.js print-bucket-acl my-bucket |
63 | | - node acl.js print-bucket-acl-for-user my-bucket [email protected] |
64 | | - node acl.js add-bucket-owner my-bucket [email protected] |
65 | | - node acl.js remove-bucket-owner my-bucket [email protected] |
66 | | - node acl.js add-bucket-default-owner my-bucket [email protected] |
67 | | - node acl.js remove-bucket-default-owner my-bucket [email protected] |
68 | | - node acl.js print-file-acl my-bucket file.txt |
69 | | - node acl.js print-file-acl-for-user my-bucket file.txt [email protected] |
70 | | - node acl.js add-file-owner my-bucket file.txt [email protected] |
71 | | - node acl.js remove-file-owner my-bucket file.txt [email protected] |
72 | | -
|
73 | | -For more information, see https://cloud.google.com/storage/docs/access-control/create-manage-lists |
74 | | -``` |
75 | | - |
76 | | -[acl_0_docs]: https://cloud.google.com/storage/docs/access-control/create-manage-lists |
77 | | -[acl_0_code]: acl.js |
78 | | - |
79 | | -### Buckets |
80 | | - |
81 | | -View the [documentation][buckets_1_docs] or the [source code][buckets_1_code]. |
82 | | - |
83 | | -__Usage:__ `node buckets.js --help` |
84 | | - |
85 | | -``` |
86 | | -Commands: |
87 | | - create <bucket> Creates a new bucket. |
88 | | - list Lists all buckets in the current project. |
89 | | - delete <bucket> Deletes a bucket. |
90 | | -
|
91 | | -Options: |
92 | | - --help Show help [boolean] |
93 | | -
|
94 | | -Examples: |
95 | | - node buckets.js create my-bucket Creates a new bucket named "my-bucket". |
96 | | - node buckets.js list Lists all buckets in the current project. |
97 | | - node buckets.js delete my-bucket Deletes a bucket named "my-bucket". |
98 | | -
|
99 | | -For more information, see https://cloud.google.com/storage/docs |
100 | | -``` |
101 | | - |
102 | | -[buckets_1_docs]: https://cloud.google.com/storage/docs |
103 | | -[buckets_1_code]: buckets.js |
104 | | - |
105 | | -### Encryption |
106 | | - |
107 | | -View the [documentation][encryption_2_docs] or the [source code][encryption_2_code]. |
108 | | - |
109 | | -__Usage:__ `node encryption.js --help` |
110 | | - |
111 | | -``` |
112 | | -Commands: |
113 | | - generate-encryption-key Generate a sample encryption key. |
114 | | - upload <bucketName> <srcFilename> <destFilename> <key> Encrypts and uploads a file. |
115 | | - download <bucketName> <srcFilename> <destFilename> <key> Decrypts and downloads a file. |
116 | | - rotate <bucketName> <fileName> <oldkey> <newKey> Rotates encryption keys for a file. |
117 | | -
|
118 | | -Options: |
119 | | - --help Show help [boolean] |
120 | | -
|
121 | | -Examples: |
122 | | - node encryption.js generate-encryption-key Generate a sample encryption key. |
123 | | - node encryption.js upload my-bucket ./resources/test.txt Encrypts and uploads "resources/test.txt" to |
124 | | - file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt". |
125 | | - node encryption.js download my-bucket file_encrypted.txt Decrypts and downloads |
126 | | - ./file.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt" to "./file.txt". |
127 | | - node encryption.js rotate my-bucket file_encrypted.txt Rotates encryption keys for |
128 | | - QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q= "gs://my-bucket/file_encrypted.txt". |
129 | | -
|
130 | | -For more information, see https://cloud.google.com/storage/docs |
131 | | -``` |
132 | | - |
133 | | -[encryption_2_docs]: https://cloud.google.com/storage/docs |
134 | | -[encryption_2_code]: encryption.js |
135 | | - |
136 | | -### Files |
137 | | - |
138 | | -View the [documentation][files_3_docs] or the [source code][files_3_code]. |
139 | | - |
140 | | -__Usage:__ `node files.js --help` |
141 | | - |
142 | | -``` |
143 | | -Commands: |
144 | | - list <bucketName> [prefix] [delimiter] Lists files in a bucket, optionally filtering by a |
145 | | - prefix. |
146 | | - upload <bucketName> <srcFileName> Uploads a local file to a bucket. |
147 | | - download <bucketName> <srcFileName> <destFileName> Downloads a file from a bucket. |
148 | | - delete <bucketName> <fileName> Deletes a file from a bucket. |
149 | | - get-metadata <bucketName> <fileName> Gets the metadata for a file. |
150 | | - make-public <bucketName> <fileName> Makes a file public. |
151 | | - generate-signed-url <bucketName> <fileName> Generates a signed URL for a file. |
152 | | - move <bucketName> <srcFileName> <destFileName> Moves a file to a new location within the same bucket, |
153 | | - i.e. rename the file. |
154 | | - copy <srcBucketName> <srcFileName> <destBucketName> Copies a file in a bucket to another bucket. |
155 | | - <destFileName> |
156 | | -
|
157 | | -Options: |
158 | | - --help Show help [boolean] |
159 | | -
|
160 | | -Examples: |
161 | | - node files.js list my-bucket Lists files in "my-bucket". |
162 | | - node files.js list my-bucket public/ Lists files in "my-bucket" filtered by prefix "public/". |
163 | | - node files.js upload my-bucket ./file.txt Uploads "./file.txt" to "my-bucket". |
164 | | - node files.js download my-bucket file.txt ./file.txt Downloads "gs://my-bucket/file.txt" to "./file.txt". |
165 | | - node files.js delete my-bucket file.txt Deletes "gs://my-bucket/file.txt". |
166 | | - node files.js get-metadata my-bucket file.txt Gets the metadata for "gs://my-bucket/file.txt". |
167 | | - node files.js make-public my-bucket file.txt Makes "gs://my-bucket/file.txt" public. |
168 | | - node files.js move my-bucket file.txt file2.txt Renames "gs://my-bucket/file.txt" to |
169 | | - "gs://my-bucket/file2.txt". |
170 | | - node files.js copy my-bucket file.txt my-other-bucket Copies "gs://my-bucket/file.txt" to |
171 | | - file.txt "gs://my-other-bucket/file.txt". |
172 | | -
|
173 | | -For more information, see https://cloud.google.com/storage/docs |
174 | | -``` |
175 | | - |
176 | | -[files_3_docs]: https://cloud.google.com/storage/docs |
177 | | -[files_3_code]: files.js |
178 | | - |
179 | | -### Storage Transfer API |
180 | | - |
181 | | -View the [documentation][transfer_4_docs] or the [source code][transfer_4_code]. |
182 | | - |
183 | | -__Usage:__ `node transfer.js --help` |
184 | | - |
185 | | -``` |
186 | | -Commands: |
187 | | - jobs <cmd> [args] Run a job command. |
188 | | - operations <cmd> [args] Run an operation command. |
189 | | -
|
190 | | -Options: |
191 | | - --help Show help [boolean] |
192 | | -
|
193 | | -Examples: |
194 | | - node transfer.js jobs --help Show job commands. |
195 | | - node transfer.js operations --help Show operations commands. |
196 | | -
|
197 | | -For more information, see https://cloud.google.com/storage/transfer |
198 | | -``` |
199 | | - |
200 | | -[transfer_4_docs]: https://cloud.google.com/storage/transfer |
201 | | -[transfer_4_code]: transfer.js |
202 | | - |
203 | | -### Requester Pays samples |
204 | | - |
205 | | -View the [documentation][requesterPays_5_docs] or the [source code][requesterPays_5_code]. |
206 | | - |
207 | | -__Usage:__ `node requesterPays.js --help` |
208 | | - |
209 | | -``` |
210 | | -Commands: |
211 | | - enable <bucket> Enables requester-pays requests on a bucket. |
212 | | - disable <bucket> Disables requester-pays requests on a bucket. |
213 | | - get-status <bucket> Determines whether requester-pays requests are enabled on a |
214 | | - bucket. |
215 | | - download <bucketName> <srcFileName> <destFileName> Downloads a file from a bucket using requester-pays requests. |
216 | | -
|
217 | | -Options: |
218 | | - --help Show help [boolean] |
219 | | -
|
220 | | -Examples: |
221 | | - node requesterPays.js enable my-bucket Enables requester-pays requests on a bucket named |
222 | | - "my-bucket". |
223 | | - node requesterPays.js disable my-bucket Disables requester-pays requests on a bucket named |
224 | | - "my-bucket". |
225 | | - node requesterPays.js get-status my-bucket Determines whether requester-pays requests are enabled |
226 | | - for a bucket named "my-bucket". |
227 | | - node requesterPays.js download my-bucket file.txt ./file.txt Downloads "gs://my-bucket/file.txt" to "./file.txt" |
228 | | - using requester-pays requests. |
229 | | -
|
230 | | -For more information, see https://cloud.google.com/storage/docs |
231 | | -``` |
232 | | - |
233 | | -[requesterPays_5_docs]: https://cloud.google.com/storage/docs |
234 | | -[requesterPays_5_code]: requesterPays.js |
235 | | - |
236 | | -## Running the tests |
237 | | - |
238 | | -1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. |
239 | | - |
240 | | -1. Run the tests: |
241 | | - |
242 | | - With **npm**: |
243 | | - |
244 | | - npm test |
245 | | - |
246 | | - With **yarn**: |
247 | | - |
248 | | - yarn test |
| 4 | +[client]: https://github.com/googleapis/nodejs-storage |
| 5 | +[samples]: https://github.com/googleapis/nodejs-storage/tree/master/samples |
0 commit comments