Skip to content

Commit 23cab9a

Browse files
authored
Merge pull request #285 from iOSOfSunXp/master
QNFormUpload addParam:fileName
2 parents e1864f8 + 5698421 commit 23cab9a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

QiniuSDK/Storage/QNFormUpload.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
- (instancetype)initWithData:(NSData *)data
1717
withKey:(NSString *)key
18+
withFileName:(NSString *)fileName
1819
withToken:(QNUpToken *)token
1920
withCompletionHandler:(QNUpCompletionHandler)block
2021
withOption:(QNUploadOption *)option

QiniuSDK/Storage/QNFormUpload.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ @interface QNFormUpload ()
2525
@property (nonatomic, strong) QNUploadOption *option;
2626
@property (nonatomic, strong) QNUpCompletionHandler complete;
2727
@property (nonatomic, strong) QNConfiguration *config;
28+
@property (nonatomic, strong) NSString *fileName;
2829
@property (nonatomic) float previousPercent;
2930

3031
@property (nonatomic, strong) NSString *access; //AK
@@ -35,6 +36,7 @@ @implementation QNFormUpload
3536

3637
- (instancetype)initWithData:(NSData *)data
3738
withKey:(NSString *)key
39+
withFileName:(NSString *)fileName
3840
withToken:(QNUpToken *)token
3941
withCompletionHandler:(QNUpCompletionHandler)block
4042
withOption:(QNUploadOption *)option
@@ -48,6 +50,7 @@ - (instancetype)initWithData:(NSData *)data
4850
_complete = block;
4951
_httpManager = http;
5052
_config = config;
53+
_fileName = fileName != nil ? fileName : @"?";
5154
_previousPercent = 0;
5255
_access = token.access;
5356
}
@@ -56,11 +59,8 @@ - (instancetype)initWithData:(NSData *)data
5659

5760
- (void)put {
5861
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
59-
NSString *fileName = _key;
6062
if (_key) {
6163
parameters[@"key"] = _key;
62-
} else {
63-
fileName = @"?";
6464
}
6565
parameters[@"token"] = _token.token;
6666
[parameters addEntriesFromDictionary:_option.params];
@@ -119,7 +119,7 @@ - (void)put {
119119
[_httpManager multipartPost:thirdHost
120120
withData:_data
121121
withParams:parameters
122-
withFileName:fileName
122+
withFileName:_fileName
123123
withMimeType:_option.mimeType
124124
withCompleteBlock:thirdComplete
125125
withProgressBlock:p
@@ -129,7 +129,7 @@ - (void)put {
129129
[_httpManager multipartPost:nextHost
130130
withData:_data
131131
withParams:parameters
132-
withFileName:fileName
132+
withFileName:_fileName
133133
withMimeType:_option.mimeType
134134
withCompleteBlock:retriedComplete
135135
withProgressBlock:p
@@ -139,7 +139,7 @@ - (void)put {
139139
[_httpManager multipartPost:upHost
140140
withData:_data
141141
withParams:parameters
142-
withFileName:fileName
142+
withFileName:_fileName
143143
withMimeType:_option.mimeType
144144
withCompleteBlock:complete
145145
withProgressBlock:p

QiniuSDK/Storage/QNUploadManager.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ - (void)putData:(NSData *)data
119119
token:(NSString *)token
120120
complete:(QNUpCompletionHandler)completionHandler
121121
option:(QNUploadOption *)option {
122+
[self putData:data fileName:nil key:key token:token complete:completionHandler option:option];
123+
}
124+
125+
- (void)putData:(NSData *)data
126+
fileName:(NSString *)fileName
127+
key:(NSString *)key
128+
token:(NSString *)token
129+
complete:(QNUpCompletionHandler)completionHandler
130+
option:(QNUploadOption *)option {
122131
if ([QNUploadManager checkAndNotifyError:key token:token input:data complete:completionHandler]) {
123132
return;
124133
}
@@ -152,6 +161,7 @@ - (void)putData:(NSData *)data
152161
QNFormUpload *up = [[QNFormUpload alloc]
153162
initWithData:data
154163
withKey:key
164+
withFileName:fileName
155165
withToken:t
156166
withCompletionHandler:complete
157167
withOption:option
@@ -193,7 +203,8 @@ - (void)putFileInternal:(id<QNFileDelegate>)file
193203

194204
if ([file size] <= _config.putThreshold) {
195205
NSData *data = [file readAll];
196-
[self putData:data key:key token:token complete:complete option:option];
206+
NSString *fileName = [[file path] lastPathComponent];
207+
[self putData:data fileName:fileName key:key token:token complete:completionHandler option:option];
197208
return;
198209
}
199210

0 commit comments

Comments
 (0)