上传文件有问题。我正在将文件从objective-c发送到java;
服务器端:
记录器没有出现在tomcat中。
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody MessageWrapper getMessage(@RequestBody MessageWrapper msg, @RequestParam("photo") MultipartFile file) throws Exception {
logger.info("Send");
/*
my code
*/
return msg;
}
客户端:
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setData:message.imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
NSArray *toEmail = [message.to componentsSeparatedByString:@","];
NSArray *objects = [NSArray arrayWithObjects:toEmail, message.subject, message.content, nil];
NSArray *keys = [NSArray arrayWithObjects:@"to", @"subject", @"body", nil];
NSDictionary *msgDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *jsonRequest = [msgDict JSONRepresentation];
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[request setRequestMethod:@"POST"];
[request setUseCookiePersistence:NO];
[request addRequestHeader:@"Content-type" value:@"application/json"];
[request setRequestCookies:[NSMutableArray arrayWithObject:[self setKidCookieParams]]];
[request setDelegate:self];
[request setPostBody:[[NSMutableData alloc] initWithData:requestData]];
[request startAsynchronous];
它工作正常,没有以下几行:
[request setData:message.imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
and server side like this:
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody MessageWrapper sendMessage(@RequestBody MessageWrapper msg) throws Exception {
logger.info("Send");
/*
my code
*/
return msg;
}
请帮我。提前致谢!