1

次のコードチャンクは、画像ファイルをデータベースに送信するために使用されます。動作を停止しました:印刷してもSUCCESS、サーバーに画像が表示されません。これをデバッグする方法について何かアドバイスはありますか?

編集

デバッガーでimageDataを出力し、メモリアドレスの配列を取得したので、画像があるとほぼ確信しています。

- (void)postActivityImage:(Spot*)localSpot
{
    NSLog(@"%s",__func__);
    NSString *url = [NSString stringWithFormat:@"v1/activity/%@/image", localSpot.uniqueID];
    UIImage *image = [UIImage imageWithContentsOfFile:localSpot.imageLocalURL];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5f);
    NSURLRequest *request = [httpClient_ multipartFormRequestWithMethod:@"POST"
                                                                   path:url 
                                                             parameters:nil 
                                              constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                                                  [formData appendPartWithFileData:imageData 
                                                                              name:@"test" 
                                                                          fileName:@"test" 
                                                                          mimeType:@"image/jpeg"];
                                              }];

    AFJSONRequestOperation *ro;
    ro = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                         success:^(NSURLRequest *request, NSURLResponse *response, id JSON) {
                                                             NSLog(@"success: %@", JSON);
                                                             NSLog(@"SUCCESS - IMAGE POSTED.");
                                                             [self updateSpotSubmitInProgressStatusWithActivityFinished:ImagePost andSuccess:YES];
                                                             [[NSNotificationCenter defaultCenter] postNotificationName:SUBMIT_STATUS object:self userInfo:nil];
                                                             self.spot.imageSubmitted = YES;
                                                         } failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON) {
                                                             [self updateSpotSubmitInProgressStatusWithActivityFinished:ImagePost andSuccess:NO];
                                                             NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:error, @"Error", nil];
                                                             [[NSNotificationCenter defaultCenter] postNotificationName:SUBMIT_STATUS object:self userInfo:dic];
                                                             NSLog(@"%s   ERROR: %@", __func__, error);
                                                             NSLog(@"%s   RESPONSE: %@",__func__, response);
                                                             NSLog(@"%s   FAIL   json response: %@",__func__, JSON);
                                                         }];

    [httpClient_ enqueueHTTPRequestOperation:ro];
}
4

1 に答える 1

6

HTTP 接続をデバッグするときの私の頼りになるツールはCharlesです。デスクトップ コンピューターに Charles をセットアップし、それを iPhone のプロキシとして構成してから、iPhone が生成する HTTP トラフィックを監視できます。その後、リクエストが行われているかどうかを確認し、行われている場合は、各リクエストを詳細に調べます。

iPhone のHTTPトラフィックを表示するように Charles をセットアップするための適切な手順を次に示します。

于 2012-06-01T14:53:39.397 に答える