Swift Firebase Storage How to retrieve image with unknow name(NSUUID)

后端 未结 2 1216
伪装坚强ぢ
伪装坚强ぢ 2021-01-16 07:03

I am making a function to retrieve the url as the user Image. However, my upload image name function created by NSUUID. Therefore, I would not know what is the name of each

2条回答
  •  臣服心动
    2021-01-16 07:34

    There can be two ways to go about this :-

    1.) Store the Firebase Storage path of users profile_picture in your Firebase database and retrieve every time before you start downloading your profile picture.

    2.) Store the file path in CoreData every time your user uploads a profile picture and hit that path every time to get file_Path to where you stored that user's profile_pic .

    Storing the path :-

    func uploadSuccess(metadata : FIRStorageMetadata , storagePath : String)
    {   
        print("upload succeded!")
        print(storagePath)
    
        NSUserDefaults.standardUserDefaults().setObject(storagePath, forKey: "storagePath.\((FIRAuth.auth()?.currentUser?.uid)!)")
        //Setting storagePath : (file path of your profile pic in firebase) to a unique key for every user "storagePath.\((FIRAuth.auth()?.currentUser?.uid)!)"
        NSUserDefaults.standardUserDefaults().synchronize()
    
     }
    

    Retrieving your path, Every time you start downloading your image :-

    let storagePathForProfilePic = NSUserDefaults.standardUserDefaults().objectForKey("storagePath.\((FIRAuth.auth()?.currentUser?.uid)!)") as? String
    

    Note :- i am using currentUser ID, you can use USER SPECIFIC id ,if you want to download multiple users profile pics, all you need to do is put their uid in place.

提交回复
热议问题