【问题标题】:iOS Dropbox error loading thumbnailsiOS Dropbox 加载缩略图时出错
【发布时间】:2015-11-09 19:14:18
【问题描述】:

我想获取在视图上显示的 Dropbox 文件的缩略图。我知道我必须使用 loadThumbnail 方法,但我不知道该怎么做。

我写了这个:

for file in dropboxMetadata.contents {
        dbRestClient.loadThumbnail(file.path, ofSize: "s", intoPath: "https://api-content.dropbox.com/1/thumbnails/auto/")
}

但我得到一些这样的错误:

error making request to /1/thumbnails/dropbox/star.jpg - (4) Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed.

感谢您的帮助!

【问题讨论】:

  • 展示你的“- (void)restClient:(DBRestClient *)client loadedThumbnail:(NSString *)destPath metadata:(DBMetadata *)metadata”实现
  • intoPath 必须是您可以在本地写入的位置。
  • 如果我是对的,我必须把缩略图放在我自己的网址上吗? @MichaelDautermann 我还没有看到这个方法,所以当缩略图准备好时,我可以在我的视图中放置图像?
  • 所以我用这个替换了方法:client.loadThumbnail("https://api-content.dropbox.com/1/thumbnails/auto/", ofSize: "s", intoPath: "http://myUrl"),我得到了这个错误:error making request to /1/thumbnails/dropboxhttps://api-content.dropbox.com/1/thumbnails/auto - (400) Expected 'root' to be 'dropbox', 'sandbox', or 'auto', got u'dropboxhttps:'
  • path 是文件系统路径,而不是 URL。

标签: ios swift thumbnails dropbox


【解决方案1】:

Petesh 的想法是正确的。 intoPath 是这些缩略图的目标目录。

试试这个:

    func createTempDirectory() -> String? {
    let tempDirectoryTemplate = NSTemporaryDirectory().stringByAppendingPathComponent("XXXXX")

    let fileManager = NSFileManager.defaultManager()

    var err: NSErrorPointer = nil

    // remove any previous temporary folder that's there, in case it's there
    fileManager.removeItemAtPath(tempDirectoryTemplate)

    if fileManager.createDirectoryAtPath(tempDirectoryTemplate, withIntermediateDirectories: true, attributes: nil, error: err) {
        return tempDirectoryTemplate
    } else {
        print("can't create temporary directory at \(tempDirectoryTemplate)")
        return nil
    }
}

我找到in this question的上述代码

然后您可以更改自己的代码以执行以下操作:

let temporaryDirectory = createTempDirectory()
for file in dropboxMetadata.contents {
        dbRestClient.loadThumbnail(file.path, ofSize: "s", intoPath: temporaryDirectory)
}

如果可行,那么您可以将“intoPath”参数更改为您认为更合适的任何目录。

【讨论】:

  • 感谢您的回答,它似乎真的有效!现在我想知道如何获取缩略图,它们是否在 url 中以他们的名字命名?比如:var imageName = temporaryDirectory + "/star.jpg" ?
  • 我怀疑是这样,但您可以列出该文件夹中的文件,看看您能找到什么。 Here is another useful question & answer that might help you.
  • 谢谢,但是当我打印 temporaryDirectory 时,它返回 nil。是这样吗?
  • 您如何以及在哪里打印它?我在上面的临时目录创建代码中添加了几行代码。
  • 我声明了tempDirectoryTemplate 并在之后做了stringByAppendingPathComponent 并且它有效。它返回:Optional("/Users/simpleandnew2/Library/Developer/CoreSimulator/Devices/2F8FD9AD-0EA5-4DE9-B2E3-553B374049EA/data/Containers/Data/Application/37567AC9-ECDC-46A4-8FFB-E0AAF1E0E4BF/tmp/")
猜你喜欢
  • 2016-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-10
  • 2012-06-17
  • 2020-05-13
  • 2018-02-13
  • 2013-04-29
相关资源
最近更新 更多