我正在快速上传视频和图像到firebase。现在,当上传完成后,我会得到图像的url。但是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)
}发布于 2017-06-23 23:02:10
我们有一个使用云函数和云存储来生成缩略图的示例:https://github.com/firebase/functions-samples/tree/master/generate-thumbnail
缩略图将保存回云存储,然后您可以下载适当大小的照片。
https://stackoverflow.com/questions/44717259
复制相似问题