【问题标题】:how to get thumbnail image from firebase after upload in ios?在ios中上传后如何从firebase获取缩略图?
【发布时间】: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


【解决方案1】:

我们有一个如何使用 Cloud Functions 和 Cloud Storage 生成缩略图的示例:https://github.com/firebase/functions-samples/tree/master/generate-thumbnail

缩略图会保存回 Cloud Storage,然后您可以下载适当大小的照片。

【讨论】:

  • 这仅适用于图像。我应该使用什么来获取视频文件的缩略图?
猜你喜欢
  • 2016-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-05
  • 2017-02-11
  • 1970-01-01
  • 2017-03-03
相关资源
最近更新 更多