Last active
May 5, 2024 15:16
-
-
Save vishwarajanand/fe4e80a06ea8fdf7d27cf963eca86344 to your computer and use it in GitHub Desktop.
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
import { Storage } from './build/esm/src/storage.js'; | |
// Path: nodejs-storage/issue_2389.js | |
const storage = new Storage(); | |
const myBucket = storage.bucket('thebookclub'); | |
const file = myBucket.file('sample.txt'); | |
file.copy('new_sample.txt', { | |
contentType: 'outer', // A property from CopyOptions | |
metadata: { | |
// Typed as FileMetadata | |
contentType: 'internal', | |
custom1: 'outer', // Not a part of FileMetadata, but allowed by TypeScript | |
metadata: { | |
// Intended to hold custom metadata, but ignored | |
custom2: 'internal', | |
}, | |
}, | |
}); | |
const new_file = myBucket.file('new_sample.txt'); | |
new_file.getMetadata((err, metadata) => { | |
console.log(metadata.metadata.custom1); // outer | |
console.log(metadata.metadata.custom2); // undefined | |
}); |
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
<?php | |
require __DIR__ . "/vendor/autoload.php"; | |
use Google\Cloud\Storage\StorageClient; | |
// Create a Storage client | |
$storage = new StorageClient([ | |
'projectId' => 'the-book-club-337319', | |
]); | |
// Define the bucket name and folder path | |
$bucketName = 'thebookclub'; | |
$bucket = $storage->bucket($bucketName); | |
$object = $bucket->object('sample.txt'); | |
$new_object = $object->copy('thebookclub', [ | |
'name' => 'sample_copy_php.txt', | |
'metadata' => [ | |
'contentType' => 'outer', | |
'metadata' => [ | |
'contentType' => 'internal', | |
'custom1' => 'outer', | |
'metadata' => [ | |
'custom2' => 'internal' | |
] | |
], | |
], | |
]); | |
print_r($new_object->info()); | |
// php library updates metadata successfully |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment