1313@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
1414
1515@property (nonatomic , strong ) NSString *token;
16- @property (nonatomic , strong ) NSString *domain;
1716@property (nonatomic , strong ) UIImage *pickImage;
1817
1918@end
@@ -40,29 +39,12 @@ - (IBAction)uploadAction:(id)sender {
4039 otherButtonTitles: nil ];
4140 [alert show ];
4241 } else {
43- [self getTokenFromQN ];
44- }
45- }
46-
47- - (void )getTokenFromQN {
48- // 1.管理器
49- AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager ];
50-
51- // //2.设置登录参数
52- // NSDictionary *dict = @{ @"username":@"xn", @"password":@"123" };
53-
54- // 3.请求
55- [manager POST: @" http://115.231.183.102:9090/api/quick_start/simple_image_example_token.php" parameters: nil success: ^(AFHTTPRequestOperation *operation, id responseObject) {
56- self.domain = responseObject[@" domain" ];
57- self.token = responseObject[@" uptoken" ];
5842 [self uploadImageToQNFilePath: [self getImagePath: self .pickImage]];
5943 }
60- failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
61- NSLog (@" %@ " , error);
62- }];
6344}
6445
6546- (void )uploadImageToQNFilePath : (NSString *)filePath {
47+ self.token = @" 你的token" ;
6648 QNUploadManager *upManager = [[QNUploadManager alloc ] init ];
6749 QNUploadOption *uploadOption = [[QNUploadOption alloc ] initWithMime: nil progressHandler: ^(NSString *key, float percent) {
6850 NSLog (@" percent == %.2f " , percent);
@@ -73,9 +55,6 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
7355 [upManager putFile: filePath key: nil token: self .token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
7456 NSLog (@" info ===== %@ " , info);
7557 NSLog (@" resp ===== %@ " , resp);
76- NSLog (@" %@ /%@ " , self.domain , resp[@" key" ]);
77- [self .preViewImage setImageWithURL: [NSURL URLWithString: [NSString stringWithFormat: @" %@ /%@ " , self .domain, resp[@" key" ]]] placeholderImage: [UIImage imageNamed: @" placeholder.jpg" ]];
78-
7958 }
8059 option: uploadOption];
8160}
0 commit comments