@@ -55,49 +55,48 @@ + (instancetype)sharedInstanceWithRecorder:(id <QNRecorderDelegate> )recorder
5555 return sharedInstance;
5656}
5757
58- + (BOOL )checkAndNotifyError : (NSString *)key
59- token : (NSString *)token
60- data : (NSData *)data
58+ + (BOOL )checkAndNotifyError : (NSString *)key
59+ token : (NSString *)token
60+ data : (NSData *)data
6161 file : (NSString *)file
62- complete : (QNUpCompletionHandler)completionHandler {
63- NSString *desc = nil ;
64- if (completionHandler == nil ) {
65- @throw [NSException exceptionWithName: NSInvalidArgumentException
66- reason: @" no completionHandler" userInfo: nil ];
67- return YES ;
68- }
69- if (data == nil && file == nil ) {
70- desc = @" no input data" ;
71- }else if (token == nil || [token isEqualToString: @" " ] ){
72- desc = @" no token" ;
73- }
74- if (desc != nil ) {
75- QNAsyncRun (^{
76- completionHandler ([QNResponseInfo responseInfoWithInvalidArgument: desc], key, nil );
77- });
78- return YES ;
79- }
80- return NO ;
62+ complete : (QNUpCompletionHandler)completionHandler {
63+ NSString *desc = nil ;
64+ if (completionHandler == nil ) {
65+ @throw [NSException exceptionWithName: NSInvalidArgumentException
66+ reason: @" no completionHandler" userInfo: nil ];
67+ return YES ;
68+ }
69+ if (data == nil && file == nil ) {
70+ desc = @" no input data" ;
71+ }
72+ else if (token == nil || [token isEqualToString: @" " ]) {
73+ desc = @" no token" ;
74+ }
75+ if (desc != nil ) {
76+ QNAsyncRun ( ^{
77+ completionHandler ([QNResponseInfo responseInfoWithInvalidArgument: desc], key, nil );
78+ });
79+ return YES ;
80+ }
81+ return NO ;
8182}
8283
83-
8484- (void )putData : (NSData *)data
8585 key : (NSString *)key
8686 token : (NSString *)token
8787 complete : (QNUpCompletionHandler)completionHandler
8888 option : (QNUploadOption *)option {
8989 NSMutableDictionary *parameters = [NSMutableDictionary dictionary ];
90-
91- if ([QNUploadManager checkAndNotifyError: key token: token data: data file: nil complete: completionHandler]){
92- return ;
93- }
9490
95- if (key && ![key isEqualToString: kQNUndefinedKey ]) {
91+ if ([QNUploadManager checkAndNotifyError: key token: token data: data file: nil complete: completionHandler]) {
92+ return ;
93+ }
94+ NSString *fileName = key;
95+ if (key) {
9696 parameters[@" key" ] = key;
9797 }
98-
99- if (!key) {
100- key = kQNUndefinedKey ;
98+ else {
99+ fileName = @" ?" ;
101100 }
102101
103102 parameters[@" token" ] = token;
@@ -152,7 +151,7 @@ - (void)putData:(NSData *)data
152151 [_httpManager multipartPost: [NSString stringWithFormat: @" http://%@ " , nextHost]
153152 withData: data
154153 withParams: parameters
155- withFileName: key
154+ withFileName: fileName
156155 withMimeType: mimeType
157156 withCompleteBlock: retriedComplete
158157 withProgressBlock: p
@@ -162,7 +161,7 @@ - (void)putData:(NSData *)data
162161 [_httpManager multipartPost: [NSString stringWithFormat: @" http://%@ " , kQNUpHost ]
163162 withData: data
164163 withParams: parameters
165- withFileName: key
164+ withFileName: fileName
166165 withMimeType: mimeType
167166 withCompleteBlock: complete
168167 withProgressBlock: p
@@ -174,17 +173,17 @@ - (void)putFile:(NSString *)filePath
174173 token : (NSString *)token
175174 complete : (QNUpCompletionHandler)completionHandler
176175 option : (QNUploadOption *)option {
177- if ([QNUploadManager checkAndNotifyError: key token: token data: nil file: filePath complete: completionHandler]){
178- return ;
179- }
176+ if ([QNUploadManager checkAndNotifyError: key token: token data: nil file: filePath complete: completionHandler]) {
177+ return ;
178+ }
180179
181180 @autoreleasepool {
182181 NSError *error = nil ;
183182 NSDictionary *fileAttr = [[NSFileManager defaultManager ] attributesOfItemAtPath: filePath error: &error];
184183
185184 if (error) {
186- QNAsyncRun ( ^{
187- QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError: error];
185+ QNAsyncRun ( ^{
186+ QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError: error];
188187 completionHandler (info, key, nil );
189188 });
190189 return ;
@@ -194,7 +193,7 @@ - (void)putFile:(NSString *)filePath
194193 UInt32 fileSize = [fileSizeNumber intValue ];
195194 NSData *data = [NSData dataWithContentsOfFile: filePath options: NSDataReadingMappedIfSafe error: &error];
196195 if (error) {
197- QNAsyncRun ( ^{
196+ QNAsyncRun ( ^{
198197 QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError: error];
199198 completionHandler (info, key, nil );
200199 });
@@ -227,9 +226,9 @@ - (void)putFile:(NSString *)filePath
227226 withRecorder: _recorder
228227 withRecorderKey: recorderKey
229228 withHttpManager: _httpManager];
230- QNAsyncRun ( ^{
231- [up run ];
232- });
229+ QNAsyncRun ( ^{
230+ [up run ];
231+ });
233232 }
234233}
235234
0 commit comments