0
나는 firebase 스토리지에 저장하고 싶은 이미지가 100 개이지만 그 이미지에서 URL을 추출해야합니다. 그것을하는 자동적 인 방법 있는가?firebase에 이미지를 여러 개 저장하고 URL을 가져 오는 중
많은 이미지를 업로드하고 URL을 자동으로 추출 할 수있는 더 나은 서비스 제공 업체가 없다면 ??
나는 firebase 스토리지에 저장하고 싶은 이미지가 100 개이지만 그 이미지에서 URL을 추출해야합니다. 그것을하는 자동적 인 방법 있는가?firebase에 이미지를 여러 개 저장하고 URL을 가져 오는 중
많은 이미지를 업로드하고 URL을 자동으로 추출 할 수있는 더 나은 서비스 제공 업체가 없다면 ??
이 작업을 수행하려면 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입니다.
Firebase Storage에는 이미지를 업로드 한 다음 차례로 다운로드 URL을 가져 오는 데 사용할 수있는 API가 있습니다. https://firebase.google.com/docs/storage/를 참조하십시오. –