1
&の画像を迅速にfirebaseにアップロードしています。アップロードが完了したら、イメージURLを取得しています。しかし、そのURLは紋章のイメージです。画像や動画をアップロードするときは、画像や動画のサムネイル画像を取得する必要があります。私は以下のコードを使用しています。iosでアップロードした後にfirebaseからサムネイル画像を取得するには?
let imagePath = withName
let metadata = FIRStorageMetadata()
metadata.contentType = mimeType
metadata.customMetadata = ["index": String(describing: index), "contentType": mimeType]
// Upload file and metadata to the object 'images/mountains.jpg'
let uploadTask = storageRef.child(imagePath).put(data, metadata: metadata)
// Listen for state changes, errors, and completion of the upload.
uploadTask.observe(.resume) { snapshot in
// Upload resumed, also fires when the upload starts
}
uploadTask.observe(.pause) { snapshot in
// Upload paused
}
uploadTask.observe(.progress) { snapshot in
// Upload reported progress
let percentComplete = Double((snapshot.progress?.completedUnitCount)!)/Double(snapshot.progress!.totalUnitCount)
progress(String(format: "%.2f", percentComplete))
print(percentComplete)
}
uploadTask.observe(.success) { snapshot in
// Upload completed successfully
//Download the the image from url and save it as Data in local directory
print(snapshot.metadata?.downloadURL()?.absoluteString ?? "no url found......")
completion(.success, (snapshot.metadata?.downloadURL()?.absoluteString), DIError.noResponse)
// self.startDownloading(downloadUrl: (snapshot.metadata?.downloadURL()?.absoluteString)!, imageName: imagePath)
}
FIRStorageは、単にデータを格納するために使用されます。自動的にサムネイルは作成されません。 Firebase Functionを使用し、サムネールを生成するためのコードを追加する必要があります。 –