Can't download a picture url from FirebaseStorage to FirebaseDatabase - Swift - metadata.downloadURL() not recognized anymore
This is the way I managed to solve my own question!
@IBAction func postButtonPressed(_ sender: Any) {
let storage = Storage.storage()
let storageRef = storage.reference()
let photoIdString = "\(NSUUID().uuidString).jpg"
let imageReference = storageRef.child("posts").child(photoIdString)
if let imageData = UIImageJPEGRepresentation(selectedImage, 0.7) {
imageReference.putData(imageData).observe(.success) { (snapshot) in
imageReference.downloadURL(completion: { (url, error) in
if let downloadUrl = url {
let directoryURL : NSURL = downloadUrl as NSURL
let urlString:String = directoryURL.absoluteString!
self.sendDataToDatabase(photoUrl: urlString)
}
else {
print("couldn't get profile image url")
return
}
})}
Quick note sendDataToDatabase is a function I have where I use the my setValue method to send the data to Firebase.
Unable to play firebase video on my iOS device
Guys no problem in my player code as I have test another video like test.mov file and its working in both solution.
- Live streaming
- Local file
So I found one answer here which help me to test my video formate.
Answer by Mike McDonald:
I have a feeling that the issue here is that the video is not in the
correct format (needs to be H.264 or MPEG-4 in .mp4, .m4v, .mov [or an
HLS video for live streaming]), and the content type should be set
appropriately (video/mp4, video/x-m4v, video/quicktime). Can you
confirm these?
Still for my satisfaction I have tried this video on Mac quick time player and got below error.
Than I realised that some time due to video formate we unable to play or stream video.
Thanks every one who helped here.
This answer is for whom who is facing same issue like me.
how to detect if Firebase url is Photo or Video - Swift
You can simply initialize an url with your link and get the path extension:
let link1 = "https://firebasestorage.googleapis.com/v0/b/myApp-1e48d.appspot.com/o/Images%2FD118DA58-C128-4E5E-BF24-AA820BEE5590.jpg?alt=media&token=49eie236-f9d1-45f8-bd0b-887382c61ccd"
if let url = URL(string: link1) {
let fileType = url.pathExtension // "jpg"
}
let link2 = "https://firebasestorage.googleapis.com/v0/b/myApp-1e48d.appspot.com/o/Videos%2F1E4B7CA0-4D0E-4AC5-9856-2F59D0811C47.mp4?alt=media&token=615teacf-0d20-48aa-bb8f-cew84a14d76d"
if let url = URL(string: link2) {
let fileType = url.pathExtension // "mp4"
}
Related Topics
Cllocationmanager and Tvos - Requestwheninuseauthorization() Not Prompting
In App Purchase in Skscene Not Working
Remove Cell When Button Pressed Inside Cell Customtableviewcell
How to Cut a Hole in a Sprite Image or Texture to Show What Is Behind It Using Spritekit in Swift
iOS Coredata Compatible with Both iOS 9 and iOS 10
Adding Data to a Specific UId in Firebase
Avoid Equatable and Hashable Boilerplate, Swift 4.2
Sklabelnode Text with Two Different Fonts and Colour. How Is This Possible
Sandbox Entitlement to Script Itunes via Nsapplescript
Performance Issue with Swiftui List
Double Variable in Mkmapitem Array
Add Value to Variable Inside Closure in Swift
How to Pull The Artist Value from Mpmediaitemcollection
Hit Fatal Error: Unexpectedly Found Nil While Unwrapping an Optional Value (Lldb)
Nstimer Scheduledtimerwithtimeinterval and Target Is "Class Level Function"