我将如何使用 Restkit 上传音频文件?我查看了文档,似乎找不到有关上传文件的任何信息。谢谢你的帮助。
问问题
3518 次
2 回答
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:@"blake@restkit.org" 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];
享受!
于 2012-08-30T14:37:52.127 回答
0
对于 Restkit 0.20,创建附件时会自动检测 MIME 类型。所以你不需要打电话
attachment.MIMEType
在构建参数时:
[params setData:imageData MIMEType:attachment.MIMEType forParam:@"image2"];
看到这个链接
于 2013-12-12T14:41:15.463 回答