gpt4 book ai didi

ios - Dropbox 2.0 Swift API : how to get Media Metadata

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:26 29 4
gpt4 key购买 nike

我正在为一个 iOS 项目使用 SwiftyDropbox 库,以递归方式获取文件夹列表,并检查文件是照片还是视频。

      client.files.getMetadata(path: fileURL, includeMediaInfo: true).response { response, error in

if let file = response as? Files.FileMetadata {
if file.mediaInfo != nil {

// ??? how to get file.mediaInfo.metadata
// specifically, I need the mediaMetadata

}
}
}

我可以看到 file.mediaInfo(如果它存在,则意味着元数据存在,但文档没有说明如何获取实际的元数据本身(特别是照片的尺寸或视频的持续时间)。

我可以从 file.mediaInfo 的描述中得到这个(并解析从中返回的字符串),但这是 hacky 并且不是 future 安全的。有没有其他方法可以获取这些数据?

这是我想从中获取数据的类(在 Files.swift 中):

public class MediaMetadata: CustomStringConvertible {
/// Dimension of the photo/video.
public let dimensions : Files.Dimensions?
/// The GPS coordinate of the photo/video.
public let location : Files.GpsCoordinates?
/// The timestamp when the photo/video is taken.
public let timeTaken : NSDate?
public init(dimensions: Files.Dimensions? = nil, location: Files.GpsCoordinates? = nil, timeTaken: NSDate? = nil) {
self.dimensions = dimensions
self.location = location
self.timeTaken = timeTaken
}
public var description : String {
return "\(prepareJSONForSerialization(MediaMetadataSerializer().serialize(self)))"
}
}

最佳答案

这是一个示例:

Dropbox.authorizedClient!.files.getMetadata(path: "/test.jpg", includeMediaInfo: true).response { response, error in
if let result = response as? Files.FileMetadata {
print(result.name)

if result.mediaInfo != nil {
switch result.mediaInfo! as Files.MediaInfo {
case .Pending:
print("Media info is pending...")
case .Metadata(let mediaMetadata):
print(mediaMetadata.dimensions)
print(mediaMetadata.location)
print(mediaMetadata.timeTaken)
}
}
} else {
print(error!)
}
}

关于ios - Dropbox 2.0 Swift API : how to get Media Metadata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925496/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com