2012-06-01 26 views
1

以下代碼塊用於將圖像文件提交到數據庫。它已停止工作:即使它打印了SUCCESS,服務器上也沒有可見的圖像。有關如何調試的建議?調試AFNetworking

編輯

我打印的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]; 
} 
+0

你說:「它已停止工作。」以前沒有變化嗎? – kevboh

+0

你可能也想在本地檢查圖像,確保它的聯網,而不是圖像本身。您可以輕鬆將圖像對象設置爲uiimageview –

回答

6

調試HTTP連接時,我的轉向工具是Charles。您可以在臺式機上設置Charles,將其配置爲iPhone上的代理,然後觀看iPhone生成的HTTP流量。然後,您可以查看是否正在創建請求,如果是,請深入檢查每個請求。

這裏是設置查爾斯查看iPhone的HTTP流量一些很好的說明:http://blog.mediarain.com/2009/08/iphone-http-connection-debugging/