0

問題は次のとおりです。

  1. imagepickerで画像を選び終わったらすぐに画像をアップロードしたい。

  2. そのため、イメージピッカーのデリゲート メソッドで 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
    

本当に何も応答しなかったので、プロセスが失敗したのか成功したのかわかりませんでした。

4

2 に答える 2

0

ピッカーのデリゲートを設定しましたか?

[yourPicker setDelegate:self]
于 2013-05-06T13:29:49.707 に答える