0
我正在創建一個應用程序,它允許用戶上傳圖像,然後在文本字段中顯示直接鏈接。使用Firebase生成下載鏈接
以下是負責將圖片上傳到我的存儲區的代碼,當用戶按下上傳按鈕時會觸發它。
@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)
如何爲用戶生成直接鏈接?
它的工作,謝謝。如何在textField上顯示downloadURL的值我試過[downloadURL = getLink.text!] –
@AhmedAlAbdulaal使用此代碼 - >'textField.text = downloadURL' –
謝謝,這對我有用[self.getLink.text =下載URL ] –