如果多个文件上载到Firebase Storage,则admin.storage.object是否包含/处理多个文件? [英] Does admin.storage.object contain/process multiple files if multiple files are uploaded to Firebase Storage?

本文介绍了如果多个文件上载到Firebase Storage,则admin.storage.object是否包含/处理多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将文件上传到Firebase存储中的单独文件夹中.事实证明,您无法使用用于存储的JavaScript Web客户端SDK来实现此目的.但是,您似乎可以使用Firebase Functions使用存储的Admin SDK来执行此操作.所以这就是我想要做的.我了解您需要先将文件下载到Firebase Functions中,然后重新上传到Storage中的新文件夹中.

I am trying to move files into separate folders in Firebase Storage once they have been uploaded. As it turns out, you can not achieve this with the the JavaScript Web Client SDK for Storage. However, it appears that you could do so with the Admin SDK for Storage using Firebase Functions. So that is what I am trying to do. I understand that you need to first download a file into your Firebase Functions and then re-upload into a new folder in Storage.

要下载文件,我需要从客户端传递它的引用,这在这里使我感到困惑.我目前正在通过listAll()函数获取客户端中所有上传的文件,该函数返回项目和前缀.我想知道是否可以使用项目或前缀,然后使用它们(项目或前缀)将文件下载到Firebase函数中.或者,我可以传递URL.但是,问题是,以后我该使用哪种方法来获取和下载它们?

To download a file, I need to pass its reference from the client and here is where it gets confusing to me. I am currently getting all the uploaded files in the client via the listAll() function which returns items and prefixes. I am wondering whether or not I can use either the items or the prefixes to then download the files into Firebase Functions using them (items or prefixes). Alternatively, I can pass the URLs. However, the question is, which method do I use to get and download them in Functions afterwards?

我知道admin.storage.object,如 https中所述: //firebase.google.com/docs/storage/extend-with-functions#trigger_a_function_on_changes .但是,它可以处理多个文件吗?换句话说,据我所知,对象是上传到Storage的一个文件,您可以使用其属性(例如object.bucket或object.name)来访问更多信息.但是,如果同时有多个文件上传,该如何一个接一个地处理它们呢?另外,如果我传递需要从客户端下载的文件的引用或URL,则admin.storage.object是正确的选择吗?因为它似乎只是处理上传到Storage的所有文件,而不是从客户端获取任何引用.

I know of admin.storage.object as explained in https://firebase.google.com/docs/storage/extend-with-functions#trigger_a_function_on_changes. However, does it handle multiples files? In other words, the object, as I understand, is one file that is uploaded to Storage and you can use its attributes such as object.bucket or object.name to access more information. However, what if there are multiple files uploaded at the same time, does it handle them one by one? Also, if I am passing the references or URLs of the files that need to be downloaded from the client, is admin.storage.object the right choice? Because it seems to simply process all the files uploaded to Storage, instead of getting any references from the client.

此外,还介绍了如何下载文件( https://firebase.google.com/docs/storage/extend-with-functions#example_image_transformation ),该代码为:await bucket.file(filePath).download({destination:tempFilePath}); 我知道文件路径基本上是已经在存储中的文件的名称(例如/someimage).但是,如果还有其他同名文件怎么办?可能下载了错误的文件?以及如何确保文件路径是我从客户端传递来的文件?

Further, there is a description of how to download a file (https://firebase.google.com/docs/storage/extend-with-functions#example_image_transformation) which is this code: await bucket.file(filePath).download({destination: tempFilePath}); I understand that the filepath is basically the name of the file that is already in Storage (ex. /someimage). But what if there are other files with the same name? Might the wrong file be downloaded? And how do I make sure that the filepath is the file that I passed from the client?

让我知道您的想法,以及我是否朝着正确的方向前进.如果您在答案中包含代码,请使用JavaScript编写.谢谢.

Let me know what your thoughts are and whether or not I am heading in the right direction. If you include a code in your answer, please write it in JavaScript for the Web. Thank you.

谢谢!

推荐答案

以下几点可能会有所帮助:

Here are some points that could help:

  • 从技术上讲,GCP存储中没有文件夹,GCS 模拟在对象名称中使用/来建立目录结构.

  • In GCP Storage technically there are no folders, GCS emulates the directory structure by using / in the names of objects.

设置云功能时已触发通过GCS对象更改,每个对象更改都是一个事件,每个事件都会触发该函数的调用(您可能有一个未处理文件的存储桶,该文件会触发该函数,并在处理时将它们移动到另一个存储桶中)

When setting a cloud function triggered by a GCS object change, each object change is an event, each event triggers an invocation of the function (you might have an bucket for unprocessed files which triggers the function and have them move to a different bucket when proccesed)

您可以考虑使用 REST API ,无需下载即可移动/复制/重命名对象

You might consider using the REST API to move/copy/rename the objects without having to download them

顺便提一下,这个问题有点太广泛了,可能这些要点可以帮助您澄清一些事情.

As a side note the question is a little too broad, possibly these points could help clarify things for you.

这篇关于如果多个文件上载到Firebase Storage,则admin.storage.object是否包含/处理多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆