2016-08-23 2 views
0

firebaseのストレージに保存する画像が100枚ありますが、そこからURLを抽出する必要もあります。それを行うための自動方法はありますか?firebaseに複数の画像を保存してURLを取得する

多くの画像をアップロードしてURLをすべて自動的に抽出できるようにする優れたサービスプロバイダが存在するのですか?

+1

Firebase Storageには、画像をアップロードしてそれぞれのダウンロードURLを取得するためのAPIがあります。 https://firebase.google.com/docs/storage/をご覧ください。 –

答えて

2

これを行うには、Firebase StorageとFirebase Realtime Databaseを一緒に使用することを強くお勧めします。これらの作品は、どのように相互作用するかを示すためにいくつかのコードは、(スウィフト)以下である:

共有:

// 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です。これを行う方法の具体例は、

関連する問題