Created
September 27, 2020 02:53
-
-
Save rememberlenny/59c87eaabca4c24fd2c40f16af675ca0 to your computer and use it in GitHub Desktop.
How to get the file size of a Google Cloud Storage object in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* TODO(developer): Uncomment the following lines before running the sample. | |
*/ | |
// const bucketName = 'Name of a bucket, e.g. my-bucket'; | |
// const filename = 'File to access, e.g. file.txt'; | |
// Imports the Google Cloud client library | |
const {Storage} = require('@google-cloud/storage'); | |
// Creates a client | |
const storage = new Storage(); | |
async function getMetadata() { | |
// Gets the metadata for the file | |
const [metadata] = await storage | |
.bucket(bucketName) | |
.file(filename) | |
.getMetadata(); | |
console.log(`File: ${metadata.name}`); | |
console.log(`Bucket: ${metadata.bucket}`); | |
console.log(`Storage class: ${metadata.storageClass}`); | |
console.log(`Self link: ${metadata.selfLink}`); | |
console.log(`ID: ${metadata.id}`); | |
console.log(`Size: ${metadata.size}`); | |
console.log(`Updated: ${metadata.updated}`); | |
console.log(`Generation: ${metadata.generation}`); | |
console.log(`Metageneration: ${metadata.metageneration}`); | |
console.log(`Etag: ${metadata.etag}`); | |
console.log(`Owner: ${metadata.owner}`); | |
console.log(`Component count: ${metadata.component_count}`); | |
console.log(`Crc32c: ${metadata.crc32c}`); | |
console.log(`md5Hash: ${metadata.md5Hash}`); | |
console.log(`Cache-control: ${metadata.cacheControl}`); | |
console.log(`Content-type: ${metadata.contentType}`); | |
console.log(`Content-disposition: ${metadata.contentDisposition}`); | |
console.log(`Content-encoding: ${metadata.contentEncoding}`); | |
console.log(`Content-language: ${metadata.contentLanguage}`); | |
console.log(`Media link: ${metadata.mediaLink}`); | |
console.log(`KMS Key Name: ${metadata.kmsKeyName}`); | |
console.log(`Temporary Hold: ${metadata.temporaryHold}`); | |
console.log(`Event-based hold: ${metadata.eventBasedHold}`); | |
console.log( | |
`Effective Expiration Time: ${metadata.effectiveExpirationTime}` | |
); | |
console.log(`Metadata: ${metadata.metadata}`); | |
} | |
getMetadata().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment