简体   繁体   English

如何在ios上传后从firebase获取缩略图?

[英]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.

相关问题 如何从iOS中的ALAsset获取视频的缩略图? - How to get thumbnail image of video from ALAsset in iOS? 如何从xml feed上传ios rss feed表格单元格的缩略图 - How to upload thumbnail image for ios rss feed table cell from xml feed iPhone iOS从Vimeo获取缩略图:如何将响应转换为图像? - iPhone iOS get thumbnail image from Vimeo : how to turn response into an image? 如何从 UIImagePickerViewcontroller 获取缩略图和原始图像? - How to get thumbnail and Original image from UIImagePickerViewcontroller? 如何从录制的视频-AVFoundation获取帧作为图像(图像作为缩略图) - How to get an frame as an Image from the Recorded Video -AVFoundation (Image as a thumbnail) 使用Firebase从ios设备上传图像-目标C - Upload image from ios device using Firebase - objective c 缩小图片大小后如何将图片上传到Firebase - How to upload the image to firebase after reducing Image size react native iOS - 如何在不播放的情况下从视频中获取缩略图? - iOS - How to get thumbnail from video without play? 如何获取图像参考并将图像上传到 Firebase? - How do I get Image reference and upload image to Firebase? MapView Annotation-iOS的缩略图图像 - Thumbnail image from MapView Annotation-iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM