0
我有100張圖片需要存儲在firebase存儲中,但我也需要從中提取網址。有沒有一種自動的方式呢?將多張圖片存儲到firebase中並獲取網址
如果不是有更好的服務提供商,允許上傳大量的圖像並自動提取網址?
我有100張圖片需要存儲在firebase存儲中,但我也需要從中提取網址。有沒有一種自動的方式呢?將多張圖片存儲到firebase中並獲取網址
如果不是有更好的服務提供商,允許上傳大量的圖像並自動提取網址?
我強烈建議使用Firebase存儲和Firebase實時數據庫來完成此操作。一些代碼來展示如何將這些碎片互動低於(SWIFT):
共享:
// Firebase services
var database: FIRDatabase!
var storage: FIRStorage!
...
// Initialize Database, Auth, Storage
database = FIRDatabase.database()
storage = FIRStorage.storage()
上傳:
let fileData = NSData() // get data...
let storageRef = storage.reference().child("myFiles/myFile")
storageRef.putData(fileData).observeStatus(.Success) { (snapshot) in
// When the image has successfully uploaded, we get it's download URL
// This "extracts" the URL, which you can then save to the RT DB
let downloadURL = snapshot.metadata?.downloadURL()?.absoluteString
// Write the download URL to the Realtime Database
let dbRef = database.reference().child("myFiles/myFile")
dbRef.setValue(downloadURL)
}
下載:
let dbRef = database.reference().child("myFiles")
dbRef.observeEventType(.ChildAdded, withBlock: { (snapshot) in
// Get download URL from snapshot
let downloadURL = snapshot.value() as! String
// Create a storage reference from the URL
let storageRef = storage.referenceFromURL(downloadURL)
// Download the data, assuming a max size of 1MB (you can change this as necessary)
storageRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in
// Do something with downloaded data...
})
})
欲瞭解更多信息,請參閱Zero to App: Develop with Firebase,它的associated source code,這是一個實際的例子。
Firebase存儲具有一個API,您可以使用該API上傳圖像,然後依次獲取每個圖像的下載URL。請參閱https://firebase.google.com/docs/storage/ –