@google-cloud/storage 1.6.0 » Class: Bucket

Bucket

class

Properties

acl

Cloud Storage uses access control lists (ACLs) to manage object and bucket access. ACLs are the mechanism you use to share objects with other users and allow other users to access your buckets and objects.

An ACL consists of one or more entries, where each entry grants permissions to an entity. Permissions define the actions that can be performed against an object or bucket (for example, READ or WRITE); the entity
defines who the permission applies to (for example, a specific user or group of users).

The acl object on a Bucket instance provides methods to get you a list of the ACLs defined on your bucket, as well as set, update, and delete them.

Buckets also have
default ACLs for all created files. Default ACLs specify permissions that all new objects added to the bucket will inherit by default. You can add, delete,
get, and update entities and permissions for these as well with Bucket#acl.default.

Property

Parameter

Cloud Storage Buckets have
default ACLs for all created files. You can add, delete, get, and update entities and permissions for these as well. The method signatures and examples
are all the same, after only prefixing the method call with default.

deleteFiles

This is not an atomic request. A delete attempt will be made for each file individually. Any one can fail, in which case only a portion of the files you intended to be deleted would have.

Operations are performed in parallel, up to 10 at once. The first error breaks the loop and will execute the provided callback with it. Specify
{ force: true } to suppress the errors until all files have had a chance to be processed.

The query object passed as the first argument will also be passed to
Bucket#getFiles.

get

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be
contained within this object as well.

Parameter

Example

var storage = require('@google-cloud/storage')();
var bucket = storage.bucket('albums');
bucket.getFiles(function(err, files) {
if (!err) {
// files is an array of File objects.
}
});
//-
// If your bucket has versioning enabled, you can get all of your files
// scoped to their generation.
//-
bucket.getFiles({
versions: true
}, function(err, files) {
// Each file is scoped to its generation.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
var callback = function(err, files, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
bucket.getFiles(nextQuery, callback);
}
// The `metadata` property is populated for you with the metadata at the
// time of fetching.
files[0].metadata;
// However, in cases where you are concerned the metadata could have
// changed, use the `getMetadata` method.
files[0].getMetadata(function(err, metadata) {});
};
bucket.getFiles({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
bucket.getFiles().then(function(data) {
var files = data[0];
});

makePrivate

You may also choose to make the contents of the bucket private by specifying
includeFiles: true. This will automatically run
File#makePrivate for every file in the bucket.

When specifying includeFiles: true, use force: true to delay execution of your callback until all files have been processed. By default, the callback is executed after the first error. Use force to
queue such errors until all files have been processed, after which they will be returned as an array as the first argument to your callback.

NOTE: This may cause the process to be long-running and use a high number of requests. Use with caution.

Parameter

options

Optional

object

Configuration options.

Values in options have the following properties:

Parameter

includeFiles

Optional

boolean

Make each file in the bucket private.

force

Optional

boolean

Queue errors occurred while making files private until all files have been processed.

makePublic

You may also choose to make the contents of the bucket publicly readable by specifying includeFiles: true. This will automatically run
File#makePublic for every file in the bucket.

When specifying includeFiles: true, use force: true to delay execution of your callback until all files have been processed. By default, the callback is executed after the first error. Use force to
queue such errors until all files have been processed, after which they will be returned as an array as the first argument to your callback.

NOTE: This may cause the process to be long-running and use a high number of requests. Use with caution.

Parameter

options

Optional

object

Configuration options.

Values in options have the following properties:

Parameter

includeFiles

Optional

boolean

Make each file in the bucket publicly readable.

force

Optional

boolean

Queue errors occurred while making files public until all files have been processed.

Parameter

The place to save your file. If given a string, the file will be uploaded to the bucket using the string as a filename. When given a File object, your local file will be uploaded to the File object's bucket and under the
File object's name. Lastly, when this argument is omitted, the file is uploaded to your bucket using the name of the local file or the path of the url relative to it's domain.

Possible values: "md5",
"crc32c", or false. By default, data integrity is validated with an MD5 checksum for maximum reliability. CRC32c will provide better performance with less reliability. You may also
choose to skip validation completely, however this is not recommended.