【发布时间】:2017-11-26 18:53:49
【问题描述】:
我正在快速将视频和图像上传到 Firebase。现在,当上传完成时,我正在获取图像 url。但网址是原始图片。我想在上传图像或视频时获得图像或视频的缩略图。我正在使用下面的代码。
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 函数并添加生成缩略图的代码。
标签: ios swift image firebase firebase-storage