gpt4 book ai didi

javascript - 通过 Google Cloud 功能上传文件时不保存元数据

转载 作者:行者123 更新时间:2023-12-02 23:03:52 25 4
gpt4 key购买 nike

我正在使用 firebase 云功能调整图像大小,并希望设置自定义元数据。

我直接从 google's documentation 复制了代码

但是,当我重新读取该文件时,它根本没有设置元数据。

export const generateThumbs = functions.storage.object().onFinalize(async object => {
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name as string; // File path in the bucket.
const contentType = object.contentType; // File content type.

const metadata: any = object.metadata || {};

// First time around this works and logs metadata.
// I set "isThumb" as false on client. It is set in
// the first run!
// In the second run, it comes back as undefined
console.log(object.metadata);

if (metadata && metadata.isThumb) {
console.log("Already a thumbnail");
return;
}
// .... later
metadata.isThumb = true;

// Override the original file with the smaller one
// I am passing it the same metadata, and yet
// when the function is triggered again, the
// metadata is undefined! This part is straight from
// google's documentation.
await bucket.upload(tempFilePath, {
destination: filePath,
metadata: metadata
});

我希望设置元数据,但它返回为未定义。

最佳答案

我明白了。它必须是:

等待bucket.upload(tempFilePath, { 目的地:文件路径, 元数据:{元数据:元数据} });

Google 文档:https://firebase.google.com/docs/storage/extend-with-functions没有提到这一点。

关于javascript - 通过 Google Cloud 功能上传文件时不保存元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57677732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com