0

這裏的問題:上傳圖片沒有響應任何

  1. 我要完成從imagepicker選擇圖像後,立即上傳圖片。

  2. 於是,我把我的代碼上傳使用imagepicker委託方法afnetworking圖像。

  3. 但它沒有任何反應。

    //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 
    

它真的沒有任何反應,所以我不知道如果這個過程失敗或成功。

+0

你試圖把斷點,看看它被調用? – 2013-03-07 04:46:17

回答

0

有你設置的選擇器的代表?

[yourPicker setDelegate:self]