将自定义数据添加到Firebase存储上传?(Adding custom data to a firebase storage upload?)

编程入门 行业动态 更新时间:2024-10-24 12:26:28
自定义数据添加到Firebase存储上传?(Adding custom data to a firebase storage upload?)

我正在将文件上传到Firebase存储,如下所示:

var storageRef = firebase.storage(); var fileRef = storageRef.ref(file.name); fileRef.put(file) .then(function (snapshot) { console.log('Uploaded a blob or file!'); window.URL.revokeObjectURL(file.preview); })

上传后,我有一个Firebase存储触发器:

export const processUploadedFile = functions.storage.object().onChange(event => { }

我想要做的就是上传一些附加的信息和原始上传文件,以便processUploadedFile知道如何处理它(例如,提取文件,将它移动到一个特殊的目录等等)。

我尝试使用这样的元数据:

var newMetadata = { customMetadata: { "Test": "value" } } fileRef.put(file, newMetadata)

但是在云存储触发器函数中,我不知道如何获取元数据,于是我退出fileMetaData,如下所示:

file.getMetadata().then((metaData)=>console.log(metaData))

但没有看到我的元数据在那里(或在返回未定义的fileMetaData [0] .metadata)

不知道我怎么能做到这一点...

I'm uploading files to firebase storage like so:

var storageRef = firebase.storage(); var fileRef = storageRef.ref(file.name); fileRef.put(file) .then(function (snapshot) { console.log('Uploaded a blob or file!'); window.URL.revokeObjectURL(file.preview); })

After the upload I have a firebase storage trigger:

export const processUploadedFile = functions.storage.object().onChange(event => { }

What I want to do is upload some additional information with the original upload so that the processUploadedFile knows what to do with it (for example extract the file, move it to a special directory, etc, etc).

I tried using metadata like so:

var newMetadata = { customMetadata: { "Test": "value" } } fileRef.put(file, newMetadata)

But on the cloud storage trigger function I don't know how to get the metadata, I logged out fileMetaData like so:

file.getMetadata().then((metaData)=>console.log(metaData))

But did not see my metadata anywhere in there (or in fileMetaData[0].metadata which returned undefined)

Not sure how I can achieve this...

最满意答案

我认为提供文件元信息将会诀窍。 这里是参考。 Firebase存储文件元数据 。 您可以使用customMetadata为文件传递自定义参数。 例如 :

customMetadata: { 'actionType': 'ACTION_CODE', 'action': 'do something info' }

您可以使用存储触发器访问此元数据,并据此采取相应措施。 以下是您可以如何实现自动提取图像元数据

I think providing file meta info will do the trick. Here is the reference. Firebase Storage File metadata. You can pass custom parameters for the file with customMetadata. For instance :

customMetadata: { 'actionType': 'ACTION_CODE', 'action': 'do something info' }

You can access this metadata with storage trigger and take the action accordingly. Here is how you can achieve that Automatically Extract Images Metadata

更多推荐

本文发布于:2023-04-27 20:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329075.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   上传   数据   Firebase   Adding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!