I want to upload image from one of my view controllers to Firebase and then I want to load the uploaded image to another view controller. Also I want this process to go on for infinite users. I have no idea how to do this.
Asked
Active
Viewed 342 times
-4
-
Seems to be an answer here : http://stackoverflow.com/questions/33644560/swift2-retrieving-images-from-firebase – Tushar Nov 22 '16 at 06:12
1 Answers
0
You have to upload the image to firebase as given below
// Data in memory let data: NSData = ... // Create a reference to the file you want to upload let riversRef = storageRef.child("images/rivers.jpg") // Upload the file to the path "images/rivers.jpg" let uploadTask = riversRef.putData(data, metadata: nil) { metadata, error in if (error != nil) { // Uh-oh, an error occurred! } else { // Metadata contains file metadata such as size, content-type, and download URL. let downloadURL = metadata!.downloadURL } }After the you can retrieve the image as below
// Create a reference to the file you want to download let islandRef = storageRef.child("images/island.jpg") // Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes) islandRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in if (error != nil) { // Uh-oh, an error occurred! } else { // Data for "images/island.jpg" is returned // ... let islandImage: UIImage! = UIImage(data: data!) } }Also you can find the complete reference in https://firebase.google.com/docs/storage/ios/
rajtharan-g
- 437
- 5
- 14