首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios上传后如何从firebase获取缩略图?

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

Stack Overflow用户
提问于 2017-06-23 16:58:50
回答 1查看 2.4K关注 0票数 3

我正在快速上传视频和图像到firebase。现在,当上传完成后,我会得到图像的url。但是url是原始图像。我想当图像或视频上传时,我应该得到一个缩略图图像或视频。我正在使用下面的代码。

代码语言:javascript
复制
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)
        }
EN

回答 1

Stack Overflow用户

发布于 2017-06-23 23:02:10

我们有一个使用云函数和云存储来生成缩略图的示例:https://github.com/firebase/functions-samples/tree/master/generate-thumbnail

缩略图将保存回云存储,然后您可以下载适当大小的照片。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44717259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档