在我的應用程序中,我必須將小於10 MB大小的圖像或視頻上傳到服務器。所以我需要在將圖像或視頻上傳到服務器之前檢查從圖像選擇器控制器中選擇的圖像或視頻的大小。自2天以來我一直在尋找答案。有沒有人可以幫助我這方面,提前感謝。我寫過像從圖片選擇器中選擇的字節中的圖像/視頻大小
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
NSLog(@"fullPathToFile:%@", fullPathToFile);
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:fullPathToFile error:&error];
if (!error)
{
NSNumber *size = [attributes objectForKey:NSFileSize];
NSLog(@"File size: %@", size);
}
但它返回null。
我如何獲得路徑 – Possible