How to get downloadURL of an existing image from firebase storage

Viewed 317

I pushed an image to firebase storage and by using Resize Images Extension, I am able to get a resized image of the same image name plus _240x320. To be clear with you I get the downloadURL of the original image, but I am not understand why I cannot get the downloadURL of the resized image. Here is my code:

func storeImageInFirebase(){
   let storeageRef = Storage.storage().reference()
   let imageName = UUID().uuidString //+ ".jpg"
   let imagesReference = storeageRef.child("images").child(imageName + ".jpg")
   let imageData = self.imgView.image!.pngData()
   let metaData = StorageMetadata()

   var imageName2 = imageName //+ "_240x320.jpg"
   let imagesReference2 = storeageRef.child("images").child(imageName2 + "_240x320.jpg")

   metaData.contentType = "image/jpg"
   imagesReference.putData(imageData!, metadata: metaData){ (metadate, error)
       in
       guard metadate != nil else{
           print("Error: \(String(describing: error?.localizedDescription))")
           return
       }
      // Fetch the download URL
       imagesReference.downloadURL(completion: {(url, error)
           in
           if error != nil {
               print("Faild to download url:", error!)
               return
           }else{
               // show the url in real database
            print("resized image url ..... \(url?.absoluteString)")
            var theUsedURL = self.imgURL = (url?.absoluteString)!
            self.sendDataToFirebase()

           }
       })

        // Fetch the download URL
         imagesReference2.downloadURL(completion: {(url, error)
         in
         if error != nil {
         print("Faild to download url:", error!)
         return
        }else{
         // show the url in real database
         print("resized image url ..... \(url?.absoluteString)")
         self.imgURL2 = (url?.absoluteString)!
         self.sendDataToFirebase()

         }
     })
   } 
}

I wrote two image references, one for the original image and the other one for resized image. I am able to get the original image, but I have error faild to download url and the image does not exist for the resized image, where I can see in the Firebase Storage that the image there. I am trying to solve this from a weeks I will appreciate any help.

0 Answers
Related