-
Notifications
You must be signed in to change notification settings - Fork 6
/
MVCloudAppFileUpload.m
90 lines (73 loc) · 2.38 KB
/
MVCloudAppFileUpload.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// MVCloudAppFileUpload.m
// Chat
//
// Created by Michaël Villar on 5/12/13.
//
//
#import "MVCloudAppFileUpload.h"
#import "MVUploadAuthorization.h"
#import "Cloud.h"
#import "MVFileUpload_Private.h"
@interface MVCloudAppFileUpload () <CLAPIEngineDelegate>
@property (strong, readonly, nonatomic) CLAPIEngine *clApiEngine;
@end
@implementation MVCloudAppFileUpload
@synthesize clApiEngine = clApiEngine_;
- (void)start
{
[self.clApiEngine uploadFileWithName:self.key
fileData:self.data
userInfo:@""];
}
#pragma mark CLAPIEngineDelegate Methods
- (void)requestDidFailWithError:(NSError *)error
connectionIdentifier:(NSString *)connectionIdentifier
userInfo:(id)userInfo
{
dispatch_async(dispatch_get_main_queue(), ^{
if([self.delegate respondsToSelector:@selector(fileUpload:didFailWithError:)])
[self.delegate fileUpload:self didFailWithError:error];
self.error = YES;
});
}
- (void)fileUploadDidProgress:(CGFloat)percentageComplete
connectionIdentifier:(NSString *)connectionIdentifier
userInfo:(id)userInfo
{
self.uploadPercentage = percentageComplete * 100;
dispatch_async(dispatch_get_main_queue(), ^{
if([self.delegate respondsToSelector:@selector(fileUpload:didProgress:)])
[self.delegate fileUpload:self didProgress:percentageComplete * 100];
});
}
- (void)fileUploadDidSucceedWithResultingItem:(CLWebItem *)item
connectionIdentifier:(NSString *)connectionIdentifier
userInfo:(id)userInfo
{
self.remoteURL = item.URL;
self.remoteURLForAsset = [[item.URL URLByAppendingPathComponent:@"download"]
URLByAppendingPathComponent:item.name];
if(self.uploadPercentage != 100)
{
self.uploadPercentage = 100;
}
self.finished = YES;
dispatch_async(dispatch_get_main_queue(), ^{
if([self.delegate respondsToSelector:@selector(fileUploadDidFinish:)])
[self.delegate fileUploadDidFinish:self];
});
}
#pragma mark Private Properties
- (CLAPIEngine*)clApiEngine
{
if(!clApiEngine_)
{
clApiEngine_ = [CLAPIEngine engineWithDelegate:self];
clApiEngine_.clearsCookies = YES;
clApiEngine_.email = self.uploadAuthorization.email;
clApiEngine_.password = self.uploadAuthorization.password;
}
return clApiEngine_;
}
@end