我在这里通过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"
虽然我可以使用相同的凭据(secret,api_key)访问通过kinvey(同一用户)创建的其他集合
调用此函数之前还有其他要求吗?
谢谢
我有同样的问题。我伸出援手,得到了Kinvey支持团队的帮助。
我通过为我上传的每个文件设置“ acl”来解决了这个问题。根据iOS文件指南的上载选项:“默认情况下,该文件仅对创建用户可用。 ”,这就是造成我问题的原因。
我现在上传这样的文件:
let metadata = KCSMetadata()
metadata.setGloballyReadable(true)
let data = UIImagePNGRepresentation(image)
KCSFileStore.uploadData(
data,
options: options: [KCSFileACL : metadata],
completionBlock: {KCSFileUploadCompletionBlock!},
progressBlock: nil)
这允许任何用户读取该特定文件。我使用aKCSUser.createAutogeneratedUser()
之后读取文件。
是的,您将可以访问同一kinvey应用程序下的其他集合,但是需要为文件集合设置权限。因此,您描述为的文件"myId"
需要设置适当的权限,然后其他用户(而不是上传文件的用户)才能下载该文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句