这是问题所在:
我想在完成从 imagepicker 中选择图像后立即上传图像。
所以,我把我的代码放在 imagepicker 委托方法中使用 afnetworking 上传图像。
但它没有任何反应。
//set the imageview to current image after choosing profilePic.image = image; //dismiss the imagepicker [picker dismissModalViewControllerAnimated:YES]; //start upload image code NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: @"steventi1901", @"username", UIImagePNGRepresentation(profilePic.image), @"profile_pic", nil]; AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:updateProfile]; NSData *imageToUpload = UIImagePNGRepresentation(profilePic.image); NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"PUT" path:@"" parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { [formData appendPartWithFileData: imageToUpload name:@"file" fileName:@"temp.png" mimeType:@"image/png"]; //NSLog(@"dalem"); }]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSString *response = [operation responseString]; NSLog(@"response: [%@]",response); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if([operation.response statusCode] == 403){ NSLog(@"Upload Failed"); return; } NSLog(@"error: %@", [operation error]); }]; [operation start]; //end upload image code
它真的没有任何反应,所以我不知道这个过程是失败还是成功。