我正在将文件上传到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
更多推荐
发布评论