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/ –