2012-08-30 6 views

답변

4

이 기사는 방법에 대해 설명 : http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/

발췌 :

NSString* myFilePath = @"/some/path/to/picture.gif"; 
RKParams* params = [RKParams params]; 

// Set some simple values -- just like we would with NSDictionary 
[params setValue:@"Blake" forParam:@"name"]; 
[params setValue:@"[email protected]" forParam:@"email"]; 

// Create an Attachment 
RKParamsAttachment* attachment = [params setFile:myFilePath forParam:@"image1"]; 
attachment.MIMEType = @"image/gif"; 
attachment.fileName = @"picture.gif"; 

// Attach an Image from the App Bundle 
UIImage* image = [UIImage imageNamed:@"another_image.png"]; 
NSData* imageData = UIImagePNGRepresentation(image); 
[params setData:imageData MIMEType:@"image/png" forParam:@"image2"]; 

// Let's examine the RKRequestSerializable info... 
NSLog(@"RKParams HTTPHeaderValueForContentType = %@", [params HTTPHeaderValueForContentType]); 
NSLog(@"RKParams HTTPHeaderValueForContentLength = %d", [params HTTPHeaderValueForContentLength]); 

// Send a Request! 
[[RKClient sharedClient] post:@"/uploadImages" params:params delegate:self]; 

즐기십시오!

+0

를 참조하십시오! 감사합니다 – Wasim

+0

일반 시야에 숨어 있습니다 .-) 문제 없음 :) –

+0

MIMEType이 필요 없다고 생각합니다. 자동으로 감지됩니다 ... – giuseppe

0

Restkit 0.20의 경우 첨부 파일을 만들 때 MIME 형식이 자동으로 검색됩니다. 그래서 당신은

attachment.MIMEType 

를 호출 할 필요가 그리고 PARAMS 구축 할 때하지 않습니다

[params setData:imageData MIMEType:attachment.MIMEType forParam:@"image2"]; 

을 내가 해당 페이지를 찾을 수 없습니다 방법의 하나이 link

+0

OK, 죄송합니다. 게시물을 다시 편집했습니다. – giuseppe

관련 문제