Firebase存储覆盖文件 [英] Firebase Storage Overwriting Files

查看:35
本文介绍了Firebase存储覆盖文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序中有小错误.

我的应用中有Firebase存储.我想让用户将图像上传到存储设备.

I have firebase Storage in my app. I wanna let the user to upload image to the storage.

问题是用户上载图片然后尝试上载另一张图片.该程序将覆盖以前上传的图像.

the thing is when the user uploads image and then tries to upload another image. what the program does it overwrites the image was uploaded before.

我想要的是在用户要上传其他图像时避免覆盖".并将两个图片保存在不同的文件中

what I want is to avoid "overwrite" when the user wants to upload another image. and keep both images in different file

let currentUser = Auth.auth().currentUser
    let StorageRefrenece = Storage.storage().reference()
    let posterImageRef =
        StorageRefrenece.child("posters").child(currentUser!.uid).child("posterOne.jpg")

Thnx

推荐答案

之所以发生这种情况,是因为您要使用相同的名称存储它们.在Firebase Storage中,您是负责确定文件名称的人,没有" .childByAutoId()".

That is happening because you're storing them with the same name. In Firebase Storage you're the one in charge to decide the name of the files, there is no ".childByAutoId()".

如果要使用其他文件,则可以创建随机值来命名它们,这在此处有很好的解释:

If you want to have different files, you can create random values to name them, that is well explained here: How does one generate a random number in Apple's Swift language?

您的最终代码应如下所示:

Your final code should look like this:

StorageRefrenece.child("posters").child(currentUser!.uid).child(<#Any Random Value#>)

这篇关于Firebase存储覆盖文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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