【问题标题】:Downloading Files from Kinvey in iOS在 iOS 中从 Kinvey 下载文件
【发布时间】:2016-03-25 07:59:54
【问题描述】:

我在这里阅读过有关 kinvey 的文档: http://devcenter.kinvey.com/ios/guides/files#DownloadingtoCachesDirectory

他们也提供了示例函数:

[KCSFileStore downloadData:@"myId" completionBlock:^(NSArray *downloadedResources, NSError *error) {
if (error == nil) {
    KCSFile* file = downloadedResources[0];
    NSData* fileData = file.data;
    id outputObject = nil;
    if ([file.mimeType hasPrefix:@"text"]) {
        outputObject = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
    } else if ([file.mimeType hasPrefix:@"image"]) {
        outputObject = [UIImage imageWithData:fileData];
    }
    NSLog(@"downloaded: %@", outputObject);
} else {
    NSLog(@"Got an error: %@", error);
 }
} progressBlock:nil]; 

但是当我用文件 id 替换“myId”时,它给了我这个错误:

Error Domain=KCSServerErrorDomain Code=401 "The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials"

虽然我可以使用相同的凭据(秘密、api_key)访问我通过 kinvey(同一用户)创建的其他集合

在调用这个函数之前还有什么要求吗?

谢谢

【问题讨论】:

    标签: ios objective-c iphone download kinvey


    【解决方案1】:

    我遇到了同样的问题。我联系了 kinvey 支持团队的 got help

    我通过为我上传的每个文件设置“acl”解决了这个问题。根据iOS Files guide under upload options:“默认情况下,该文件仅对创建用户可用。”,这就是导致我遇到问题的原因。

    我现在上传这样的文件:

        let metadata = KCSMetadata()
        metadata.setGloballyReadable(true)
    
        let data = UIImagePNGRepresentation(image)
    
        KCSFileStore.uploadData(
            data,
            options: options: [KCSFileACL : metadata],
            completionBlock: {KCSFileUploadCompletionBlock!},
            progressBlock: nil)
    

    这允许任何用户读取该特定文件。之后我使用KCSUser.createAutogeneratedUser() 读取文件。

    是的,您将可以访问同一个kinvey应用下的其他收藏,但需要为文件收藏设置权限。因此,您描述为"myId" 的文件需要设置适当的权限,然后才能被上传文件的用户以外的其他用户下载。

    【讨论】:

      【解决方案2】:

      您必须是活跃用户才能调用此函数。您只需要确保您已成功登录即可。

      【讨论】:

      • 是的,你是对的。一个应该是活跃用户才能下载,我也是,但我最终收到了这个错误消息。
      猜你喜欢
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 2016-02-26
      • 1970-01-01
      • 2015-05-21
      相关资源
      最近更新 更多