简体   繁体   English

iOS Dropbox错误加载缩略图

[英]iOS Dropbox error loading thumbnails

I wanna get thumbnails for dropbox files that I display on a view. 我想获得我在视图上显示的dropbox文件的缩略图。 I know that I've to use the loadThumbnail method, but I don't get exactly how to do it. 我知道我要使用loadThumbnail方法,但我不知道如何做到这一点。

I wrote this : 我写了这个:

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

but I get some errors like this : 但我得到一些像这样的错误:

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

Thanks for your help ! 谢谢你的帮助 !

Petesh has the right idea. Petesh有正确的想法。 intoPath is the destination directory for those thumbnails. intoPath是这些缩略图的目标目录。

Try this: 尝试这个:

    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
    }
}

The above code for which I found in this question 在这个问题中找到的上述代码

Then you could change your own code to do something like: 然后你可以改变你自己的代码来做类似的事情:

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

If this works, then you could change the " intoPath " parameter into any directory you think is more appropriate. 如果这样做,那么您可以将“ intoPath ”参数更改为您认为更合适的任何目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM