Skip to content

Commit 8e429a4

Browse files
committed
Merge pull request #738 from ParsePlatform/nlutsenko.files
Fixed not set url for new file uploads.
2 parents 483da23 + c0f59d0 commit 8e429a4

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

Parse/Internal/File/Controller/PFFileController.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@class BFTask<__covariant BFGenericType>;
1919
@class PFFileState;
2020
@class PFFileStagingController;
21+
@class PFFileDataStream;
2122

2223
@interface PFFileController : NSObject
2324

@@ -51,9 +52,9 @@
5152
5253
@return `BFTask` with a result set to `nil`.
5354
*/
54-
- (BFTask *)downloadFileAsyncWithState:(PFFileState *)fileState
55-
cancellationToken:(BFCancellationToken *)cancellationToken
56-
progressBlock:(PFProgressBlock)progressBlock;
55+
- (BFTask<PFVoid> *)downloadFileAsyncWithState:(PFFileState *)fileState
56+
cancellationToken:(BFCancellationToken *)cancellationToken
57+
progressBlock:(PFProgressBlock)progressBlock;
5758

5859
/**
5960
Downloads a file asynchronously with a given state and yields a stream to the live download of that file.
@@ -64,9 +65,9 @@
6465
6566
@return `BFTask` with a result set to live `NSInputStream` of the file.
6667
*/
67-
- (BFTask *)downloadFileStreamAsyncWithState:(PFFileState *)fileState
68-
cancellationToken:(BFCancellationToken *)cancellationToken
69-
progressBlock:(PFProgressBlock)progressBlock;
68+
- (BFTask<PFFileDataStream *> *)downloadFileStreamAsyncWithState:(PFFileState *)fileState
69+
cancellationToken:(BFCancellationToken *)cancellationToken
70+
progressBlock:(PFProgressBlock)progressBlock;
7071

7172
///--------------------------------------
7273
#pragma mark - Upload
@@ -83,17 +84,17 @@
8384
8485
@return `BFTask` with a result set to `PFFileState` of uploaded file.
8586
*/
86-
- (BFTask *)uploadFileAsyncWithState:(PFFileState *)fileState
87-
sourceFilePath:(NSString *)sourceFilePath
88-
sessionToken:(NSString *)sessionToken
89-
cancellationToken:(BFCancellationToken *)cancellationToken
90-
progressBlock:(PFProgressBlock)progressBlock;
87+
- (BFTask<PFFileState *> *)uploadFileAsyncWithState:(PFFileState *)fileState
88+
sourceFilePath:(NSString *)sourceFilePath
89+
sessionToken:(NSString *)sessionToken
90+
cancellationToken:(BFCancellationToken *)cancellationToken
91+
progressBlock:(PFProgressBlock)progressBlock;
9192

9293
///--------------------------------------
9394
#pragma mark - Cache
9495
///--------------------------------------
9596

96-
- (BFTask *)clearFileCacheAsync;
97+
- (BFTask<PFVoid> *)clearFileCacheAsync;
9798

9899
- (NSString *)cachedFilePathForFileState:(PFFileState *)fileState;
99100

Parse/Internal/File/Controller/PFFileController.m

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ - (PFFileStagingController *)fileStagingController {
8181
#pragma mark - Download
8282
///--------------------------------------
8383

84-
- (BFTask *)downloadFileAsyncWithState:(PFFileState *)fileState
85-
cancellationToken:(BFCancellationToken *)cancellationToken
86-
progressBlock:(PFProgressBlock)progressBlock {
84+
- (BFTask<PFVoid> *)downloadFileAsyncWithState:(PFFileState *)fileState
85+
cancellationToken:(BFCancellationToken *)cancellationToken
86+
progressBlock:(PFProgressBlock)progressBlock {
8787
if (cancellationToken.cancellationRequested) {
8888
return [BFTask cancelledTask];
8989
}
@@ -131,25 +131,25 @@ - (BFTask *)downloadFileAsyncWithState:(PFFileState *)fileState
131131
}];
132132
}
133133

134-
- (BFTask *)downloadFileStreamAsyncWithState:(PFFileState *)fileState
135-
cancellationToken:(BFCancellationToken *)cancellationToken
136-
progressBlock:(PFProgressBlock)progressBlock {
134+
- (BFTask<PFFileDataStream *> *)downloadFileStreamAsyncWithState:(PFFileState *)fileState
135+
cancellationToken:(BFCancellationToken *)cancellationToken
136+
progressBlock:(PFProgressBlock)progressBlock {
137137
return [BFTask taskFromExecutor:[BFExecutor defaultPriorityBackgroundExecutor] withBlock:^id{
138-
BFTaskCompletionSource *taskCompletionSource = [BFTaskCompletionSource taskCompletionSource];
138+
BFTaskCompletionSource<PFFileDataStream *> *taskCompletionSource = [BFTaskCompletionSource taskCompletionSource];
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

@@ -261,7 +259,7 @@ - (NSString *)cacheFilesDirectoryPath {
261259
return [self.dataSource.fileManager parseCacheItemPathForPathComponent:PFFileControllerCacheDirectoryName_];
262260
}
263261

264-
- (BFTask *)clearFileCacheAsync {
262+
- (BFTask<PFVoid> *)clearFileCacheAsync {
265263
return [BFTask taskFromExecutor:[BFExecutor defaultExecutor] withBlock:^id{
266264
NSString *path = self.cacheFilesDirectoryPath;
267265
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

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)