nic*_*f89 3 xcode objective-c parse-platform
当我尝试上传大于10mb的PFFile时,我的应用程序崩溃了.我认为Parse会捕获错误,此时我可以显示警报视图,但应用程序只是崩溃了.
我的下面的代码适用于保存图像,但就像我说的,如果文件太大,它会崩溃.
我试图用if(错误)语句捕获错误,但没有运气.
PFQuery *query = [PFQuery queryWithClassName:@"Football_Clubs"];
[query getObjectInBackgroundWithId:objectId block:^(PFObject *object, NSError *error)
{
NSData *imageData = UIImagePNGRepresentation(badgeImage);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
object[@"badge_image"] = imageFile;
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (succeeded)
{
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded)
{
badgeImageView.image = nil;
[getSettingsQuery clearCachedResult];
[self loadSettings];
[progress setText:@"Saved"];
}
}];
}
} progressBlock:^(int percentDone)
{
[progress setText:[NSString stringWithFormat:@"Saving image - %d%@ complete", percentDone, @"%"]];
}];
}];
Run Code Online (Sandbox Code Playgroud)
我的控制台日志如下:
2014-07-31 12:40:47.466 Sporter [21017:60b] *由于未捕获的异常'NSInvalidArgumentException'终止app,原因:'PFFile不能大于10485760字节'*第一次抛出调用堆栈:(0x18ae1ef50 0x1973281fc 0x18ae1ee90 0x10011d550 0x1000c6ae4 0x100141334 0x197900014 0x1978fffd4 0x1979031dc 0x18addec2c 0x18addcf6c 0x18ad1dc20 0x190a05c0c 0x18de4efdc 0x1000d5218 0x19791baa0)libc ++ abi.dylib:以NSException类型的未捕获异常终止
PFFile对象的大小限制为10MB
PFFile
PFFile允许您将应用程序文件存储在云中,否则这些文件太大或太麻烦而无法放入常规PFObject中.最常见的用例是存储图像,但您也可以将其用于文档,视频,音乐和任何其他二进制数据(最多10兆字节).
摘自PFFile上的iOS指南,https: //parse.com/docs/ios_guide#files/iOS
参考答案来自这里,/sf/answers/1171039971/
在您的情况下,10485760字节表示10.48576兆字节.这是最大的文件大小.
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:yourFilePath error:nil];
unsigned long long fileSize = [attributes fileSize]; // result would be in bytes
if(fileSize <= 10485760) {
//you can continue for upload.
}else{
//file size exceeding, can't upload.
}
Run Code Online (Sandbox Code Playgroud)
然而,这是静态的,并且不可建议,因为如果PARSE会改变主意并允许上传双倍大小的文件!
| 归档时间: |
|
| 查看次数: |
2745 次 |
| 最近记录: |