[英]how to get thumbnail image from firebase after upload in ios?
I am uploading video & images to firebase in swift. 我正在迅速将视频和图像上传到firebase。 Now when upload is complete then I am getting the image url.
现在上传完成后,我得到图片网址。 But the url is of orignal image.
但网址是原始图像。 I want when image or video is uploaded the I should get a thumnbnail image for image or video.
我希望在上传图像或视频时,我应该获得图像或视频的thumnbnail图像。 I am using below code.
我正在使用下面的代码。
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)
}
We have an example of how to use Cloud Functions with Cloud Storage to generate thumbnails: https://github.com/firebase/functions-samples/tree/master/generate-thumbnail 我们有一个如何使用Cloud Functions with Cloud Storage生成缩略图的示例: https : //github.com/firebase/functions-samples/tree/master/generate-thumbnail
Thumbnails get saved back to Cloud Storage, and you can then download the appropriately sized photo. 缩略图将保存回云存储,然后您可以下载相应大小的照片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.