これは、ファイルをアップロードするための私の POST 要求です。実際に送信する前に、サーバーに送信している JSON を NSLog に記録するにはどうすればよいですか?
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:twitid forKey:@"twit"];
[dict setObject:hash forKey:@"hash"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
if ([mediaFile isKindOfClass:[UIImage class]])
{
imageData = UIImageJPEGRepresentation(mediaFile, 0.5);
}
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:nil parameters:dict constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
if ([mediaFile isKindOfClass:[UIImage class]])
{
[formData appendPartWithFileData:imageData name:@"media" fileName:@"picture.png" mimeType:@"image/png"];
}
else if(isThisAudio)
{
[formData appendPartWithFileData:mediaFile name:@"media" fileName:@"audio.caf" mimeType:@"audio/caf"];
}
else
{
[formData appendPartWithFileData:mediaFile name:@"media" fileName:@"movie.mov" mimeType:@"video/quicktime"];
}
}];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSDictionary *jsonDictionary = JSON;
NSLog(@"jsonDictionary: %@",jsonDictionary);
}
failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON)
{
NSLog(@"Failed: %@",[error localizedDescription]);
}];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
percentDone = ((float)((int)totalBytesWritten) / (float)((int)totalBytesExpectedToWrite));
NSLog(@"Uploaded %f",percentDone);
}];
[httpClient enqueueHTTPRequestOperation:operation];