And*_*tya 2 javascript node.js google-cloud-storage google-cloud-platform
我的图像(托管在 Google Cloud Storage 中)的元数据具有名为 的属性downloaded,如果图像已下载,则downloaded键中的值将从 更改0为1。
https://cloud.google.com/storage/docs/viewing-editing-metadata#storage-view-object-metadata-nodejs中的代码显示了如何查看元数据,但并未真正涵盖如何更改元数据。
有可能这样做吗?
对的,这是可能的。
这样做的File.setMetadata()方法是使用方法。
例如,要将元数据添加到 GCS 中的对象:
const file = storage
.bucket(bucketName)
.file(filename)
const metadata = {
metadata: {
example: 'test'
}
}
file.setMetadata(metadata)
// Get the updated Metadata
const get_metadata = file.getMetadata();
// Will print `File: test`
console.log(`File: ${metadata.metadata.example}`)
Run Code Online (Sandbox Code Playgroud)
要更新它,您可以使用getMetadata()方法检索当前元数据,修改它,然后使用setMetadata()方法更新它。
例如:
const storage = new Storage();
const file = storage
.bucket(bucketName)
.file(filename)
// Get the file's metadata
const [metadata] = await file.getMetadata()
console.log(`File: ${metadata.name}`)
// update metadata
file.setMetadata(metadata.metadata.example='updated')
// Get the updated metadata
const [get_metadata] = await file.getMetadata()
console.log(`File: ${get_metadata.metadata.example}`)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1514 次 |
| 最近记录: |