I'm creating an application that lets the user upload an image and then display a direct link in a text field.
Here is the code that is responsible for uploading the image to my bucket and it is triggered when the user's press the upload button.
@IBAction func upload(_ sender: Any) {
let imageContained = viewimage.image
let storage = Storage.storage()
var storageRef = storage.reference()
storageRef = storage.reference(forURL: "bucket link")
var data = NSData()
data = UIImageJPEGRepresentation(imageContained!, 0.8)! as NSData
let dateFormat = DateFormatter()
dateFormat.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let imageName = dateFormat.string(from: NSDate() as Date)
let imagePath = "images/\(imageName).jpg"
let mountainsRef = storageRef.child(imagePath)
let metadata = StorageMetadata()
metadata.contentType = "image/jpeg"
mountainsRef.putData(data as Data, metadata: metadata)
How would I generate a direct link for the user?
Use this below function
Upload function with completion handler.
Hope it helps