Skip to content

Commit d80653a

Browse files
committed
Improve content-length calculation for file upload requests.
1 parent 749a46f commit d80653a

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,16 @@ + (instancetype)constructorWithDataSource:(id<PFInstallationIdentifierStoreProvi
9999
[request setValue:contentType forHTTPHeaderField:PFHTTPRequestHeaderNameContentType];
100100
}
101101

102-
//TODO (nlutsenko): Check for error here.
103-
NSNumber *fileSize = [PFInternalUtils fileSizeOfFileAtPath:contentFilePath error:nil];
104-
[request setValue:fileSize.stringValue forHTTPHeaderField:PFHTTPRequestHeaderNameContentLength];
102+
NSURL *fileURL = [NSURL fileURLWithPath:contentFilePath];
103+
NSNumber *fileSize = nil;
104+
NSError *error = nil;
105+
[fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:&error];
106+
if (error) {
107+
return [BFTask taskWithError:error];
108+
}
109+
if (fileSize) {
110+
[request setValue:fileSize.stringValue forHTTPHeaderField:PFHTTPRequestHeaderNameContentLength];
111+
}
105112

106113
return request;
107114
}];

Parse/Internal/PFInternalUtils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
+ (NSString *)parseServerURLString;
2323
+ (void)setParseServer:(NSString *)server;
2424

25-
+ (NSNumber *)fileSizeOfFileAtPath:(NSString *)filePath error:(NSError **)error;
26-
2725
/**
2826
Clears system time zone cache, gets the name of the time zone
2927
and caches it. This method is completely thread-safe.

Parse/Internal/PFInternalUtils.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ + (void)safePerformSelector:(SEL)selector withTarget:(id)target object:(id)objec
8686
#pragma clang diagnostic pop
8787
}
8888

89-
+ (NSNumber *)fileSizeOfFileAtPath:(NSString *)filePath error:(NSError **)error {
90-
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath
91-
error:error];
92-
return attributes[NSFileSize];
93-
}
94-
9589
///--------------------------------------
9690
#pragma mark - Serialization
9791
///--------------------------------------

0 commit comments

Comments
 (0)