Skip to content

Instantly share code, notes, and snippets.

@vishwarajanand
Last active May 5, 2024 15:16
Show Gist options
  • Save vishwarajanand/fe4e80a06ea8fdf7d27cf963eca86344 to your computer and use it in GitHub Desktop.
Save vishwarajanand/fe4e80a06ea8fdf7d27cf963eca86344 to your computer and use it in GitHub Desktop.
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
});
<?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