Skip to content

Commit b6eeafc

Browse files
committed
Fixed not set url after succesfull upload of a file.
1 parent 5a8deaf commit b6eeafc

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

Parse/Internal/File/Controller/PFFileController.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@
8383
8484
@return `BFTask` with a result set to `PFFileState` of uploaded file.
8585
*/
86-
- (BFTask *)uploadFileAsyncWithState:(PFFileState *)fileState
87-
sourceFilePath:(NSString *)sourceFilePath
88-
sessionToken:(NSString *)sessionToken
89-
cancellationToken:(BFCancellationToken *)cancellationToken
90-
progressBlock:(PFProgressBlock)progressBlock;
86+
- (BFTask<PFFileState *> *)uploadFileAsyncWithState:(PFFileState *)fileState
87+
sourceFilePath:(NSString *)sourceFilePath
88+
sessionToken:(NSString *)sessionToken
89+
cancellationToken:(BFCancellationToken *)cancellationToken
90+
progressBlock:(PFProgressBlock)progressBlock;
9191

9292
///--------------------------------------
9393
#pragma mark - Cache

Parse/Internal/File/Controller/PFFileController.m

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ - (BFTask *)downloadFileStreamAsyncWithState:(PFFileState *)fileState
139139
NSString *filePath = [self _temporaryFileDownloadPathForFileState:fileState];
140140
PFFileDataStream *stream = [[PFFileDataStream alloc] initWithFileAtPath:filePath];
141141
[[self downloadFileAsyncWithState:fileState
142-
cancellationToken:cancellationToken
143-
progressBlock:^(int percentDone) {
144-
[taskCompletionSource trySetResult:stream];
145-
146-
if (progressBlock) {
147-
progressBlock(percentDone);
148-
}
149-
}] continueWithBlock:^id(BFTask *task) {
150-
[stream stopBlocking];
151-
return task;
152-
}];
142+
cancellationToken:cancellationToken
143+
progressBlock:^(int percentDone) {
144+
[taskCompletionSource trySetResult:stream];
145+
146+
if (progressBlock) {
147+
progressBlock(percentDone);
148+
}
149+
}] continueWithBlock:^id(BFTask *task) {
150+
[stream stopBlocking];
151+
return task;
152+
}];
153153
return taskCompletionSource.task;
154154
}];
155155
}
@@ -204,11 +204,11 @@ - (NSString *)_temporaryFileDownloadPathForFileState:(PFFileState *)fileState {
204204
#pragma mark - Upload
205205
///--------------------------------------
206206

207-
- (BFTask *)uploadFileAsyncWithState:(PFFileState *)fileState
208-
sourceFilePath:(NSString *)sourceFilePath
209-
sessionToken:(NSString *)sessionToken
210-
cancellationToken:(BFCancellationToken *)cancellationToken
211-
progressBlock:(PFProgressBlock)progressBlock {
207+
- (BFTask<PFFileState *> *)uploadFileAsyncWithState:(PFFileState *)fileState
208+
sourceFilePath:(NSString *)sourceFilePath
209+
sessionToken:(NSString *)sessionToken
210+
cancellationToken:(BFCancellationToken *)cancellationToken
211+
progressBlock:(PFProgressBlock)progressBlock {
212212
if (cancellationToken.cancellationRequested) {
213213
return [BFTask cancelledTask];
214214
}
@@ -220,20 +220,18 @@ - (BFTask *)uploadFileAsyncWithState:(PFFileState *)fileState
220220

221221
PFRESTFileCommand *command = [PFRESTFileCommand uploadCommandForFileWithName:fileState.name sessionToken:sessionToken];
222222
@weakify(self);
223-
return [[[self.dataSource.commandRunner runFileUploadCommandAsync:command
224-
withContentType:fileState.mimeType
225-
contentSourceFilePath:sourceFilePath
226-
options:PFCommandRunningOptionRetryIfFailed
227-
cancellationToken:cancellationToken
228-
progressBlock:progressBlock] continueWithSuccessBlock:^id(BFTask *task) {
223+
return [[self.dataSource.commandRunner runFileUploadCommandAsync:command
224+
withContentType:fileState.mimeType
225+
contentSourceFilePath:sourceFilePath
226+
options:PFCommandRunningOptionRetryIfFailed
227+
cancellationToken:cancellationToken
228+
progressBlock:progressBlock] continueWithSuccessBlock:^id(BFTask<PFCommandResult *> *task) {
229+
@strongify(self);
229230
PFCommandResult *result = task.result;
230231
PFFileState *fileState = [[PFFileState alloc] initWithName:result.result[@"name"]
231232
urlString:result.result[@"url"]
232233
mimeType:nil];
233-
return fileState;
234-
}] continueWithSuccessBlock:^id(BFTask<PFFileState *> *task) {
235-
@strongify(self);
236-
return [self _cacheFileAsyncWithState:task.result atPath:sourceFilePath];
234+
return [[self _cacheFileAsyncWithState:fileState atPath:sourceFilePath] continueWithSuccessResult:fileState];
237235
}];
238236
}
239237

Tests/Unit/FileControllerTests.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ - (void)testUpload {
440440
progressBlock:^(int percentDone) {
441441
XCTAssertTrue(progress <= percentDone);
442442
progress = percentDone;
443-
}] continueWithBlock:^id(BFTask *task) {
444-
XCTAssertNil(task.error);
443+
}] continueWithBlock:^id(BFTask<PFFileState *> *task) {
444+
XCTAssertNotNil(task.result);
445+
XCTAssertEqualObjects(task.result.urlString, tempPath.absoluteString);
445446
[expectation fulfill];
446447
return nil;
447448
}];

0 commit comments

Comments
 (0)