gpt4 book ai didi

objective-c - 当 PFFile 太大时应用程序崩溃

转载 作者:搜寻专家 更新时间:2023-10-30 19:54:47 25 4
gpt4 key购买 nike

当我尝试上传大于 10mb 的 PFFile 时,我的应用程序崩溃了。我以为 Parse 会捕获错误,此时我可以显示警报 View ,但应用程序只是崩溃了。

我下面的代码可以很好地保存图像,但正如我所说,如果文件太大,它就会崩溃。

我试图用 if (error) 语句捕获错误,但没有成功。

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, @"%"]];
}];
}];

我的控制台日志如下:

2014-07-31 12:40:47.466 Sporter[21017:60b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“PFFile 不能大于 10485760 字节”* 首先抛出调用栈:(0x18ae1ef50 0x1973281fc 0x18ae1ee90 0x10011d550 0x1000c6ae4 0x100141334 0x197900014 0x1978fffd4 0x1979031dc 0x18addec2c 0x18addcf6c 0x18ad1dc20 0x190a05c0c 0x18de4efdc 0x1000d5218 0x19791baa0)libc++abi.dylib:以 NSException 类型的未捕获异常终止

最佳答案

PFFile 对象的大小限制为 10MB

The PFFile

PFFile lets you store application files in the cloud that would otherwise be too large or cumbersome to fit into a regular PFObject. The most common use case is storing images but you can also use it for documents, videos, music, and any other binary data (up to 10 megabytes).

摘自 PFFile 上的 iOS 指南,https://parse.com/docs/ios_guide#files/iOS

Reference answer from here, https://stackoverflow.com/a/16729142/1603234

在您的例子中,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.
}

然而,这是静态的,不可暗示,因为如果 PARSE 会改变主意并允许上传双倍大小的文件!

关于objective-c - 当 PFFile 太大时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25058014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com