我已經使用Rest Kit完成了相同的請求.Rest工具包允許在MTOM規範中發送附件。
你需要的第一件事就是下載Restkit。
以下是使用RestKit的MTOM的代碼片段。
abv.h
#import "RestKit/RestKit.h"
RKObjectManager *man;
RKObjectLoader *loader;
abc.m
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
//Start Progress bar
RKParams * params = [[RKParams alloc] init];
UIImage *image=[UIImage imageNamed:@"zbar-samples.png"];
RKObjectManager *man;
NSData * fileData=UIImageJPEGRepresentation(image,0.7);
[params setValue:@"1234" forParam:@"encryptedToken"];
[params setValue:modelObj.docNameTobeSent
forParam:@"documentName"];
RKParamsAttachment * attachments = [params setData:fileData forParam:@"file"];
[attachments setMIMEType:@"image/jpeg"];
[attachments setFileName:[NSString stringWithFormat:@"%@.jpeg",modelObj.name]];
self.man = [RKObjectManager objectManagerWithBaseURL:YOUR URL];
self.loader = [self.man loadObjectsAtResourcePathUsingPOSTRPC:@"upload.form" objectMapping:nil PostParams:params delegate:self];
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error
{
//Handle fail error
//stop Progress bar
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
{
NSLog(@"%@",@"didLoadObjects");
}
- (void)objectLoaderDidFinishLoading:(RKObjectLoader*)objectLoader
{
NSLog(@"%@",@"objectLoaderDidFinishLoading");
//stop Progress bar
}
- (void)objectLoaderDidLoadUnexpectedResponse:(RKObjectLoader*)objectLoader
{
NSLog(@"%@",@"objectLoaderDidLoadUnexpectedResponse");
//stop Progress bar
}
我也有同樣的問題。希望有人能回答這個問題。 – MiuMiu
有人設法在iOS中獲取附件? –
有關此問題的任何更新?有人爲此得到任何解決方案? – Raj