我已将此图片上传到服务器。问题是那个人怎么让服务器等待jpg文件,我在一个字符串中发送jpg编码。我能做什么?我见过的所有例子都在我的代码中发送它。
static NSString *boundary = @"---------------------------14737809831466499882746641449";
UIImage *img = [[UIImage alloc] init];
img = [UIImage imageNamed:@"tarjetaPrueba.jpg"];
NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(img, 1.0)];
NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"front\"; \r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:imageData];
[postbody appendData:[[NSString stringWithFormat:@"--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];
感谢。