My app is used uiwebview to reload the page, but page on a function of the camera to upload pictures, I wouldn't use uiwebview upload pictures, I got the following code on the Internet, but it should not be used. I don't know how to do and need your help, thank you
- (void)beginSendImage:(UIImage *)image
{
//把图片转换成imageDate格式
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
//传送路径
NSString *urlString = ShareManager.systemUrl;
if([urlString rangeOfString:@"http"].location == NSNotFound){
urlString = [NSString stringWithFormat:@"http://%@/JBIZ/AppUploadAction",urlString];
}else{
urlString = [NSString stringWithFormat:@"%@/JBIZ/AppUploadAction",urlString];
}
//建立请求对象
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init];
//设置请求路径
[request setURL:[NSURL URLWithString:urlString]];
//请求方式
[request setHTTPMethod:@"POST"];
//一连串上传头标签
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\\userfile\\; filename=\vim_go.jpg\\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
//上传文件开始
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//获得返回值
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
}