체크 아웃 꽤 좋은 튜토리얼 : 그것에 대해 매우 옳지 않아
http://iphone.zcentric.com/2008/08/29/post-a-uiimage-to-the-web/
것은 실제로 float로서 품질을 취 UIImageJPEGRepresentation에 품질 설정으로 (90)을 통과한다는 것입니다 0.0에서 1.0 사이이므로 0.9가되어야합니다. 코드가 작동한다고 확신합니다. 의도 한대로 90 % 대신 100 % 품질을 지정했습니다. 그리고, 단지 편의를 위해와 휴식을 연결할 경우, 여기 (명확성을 위해 리팩토링과 더 나은 질문에 맞게) 관련 코드 : 그것은 여기에 쓰여 나는 실제로 그것을 컴파일하지 않은 아마 그래서
- (void)uploadImage:(UIImage *)image toURL:(NSURL *)url withTitle:(NSString *)title {
// encode the image as JPEG
NSData *imageData = UIImageJPEGRepresentation(image, 0.9);
// set up the request
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
// create a boundary to delineate the file
NSString *boundary = @"14737809831466499882746641449";
// tell the server what to expect
NSString *contentType =
[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
// make a buffer for the post body
NSMutableData *body = [NSMutableData data];
// add a boundary to show where the title starts
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary]
dataUsingEncoding:NSASCIIStringEncoding]];
// add the title
[body appendData:[
@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"
dataUsingEncoding:NSASCIIStringEncoding]];
[body appendData:[title
dataUsingEncoding:NSASCIIStringEncoding]];
// add a boundary to show where the file starts
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary]
dataUsingEncoding:NSASCIIStringEncoding]];
// add a form field
[body appendData:[
@"Content-Disposition: form-data; name=\"picture\"; filename=\"image.jpeg\"\r\n"
dataUsingEncoding:NSASCIIStringEncoding]];
// tell the server to expect some binary
[body appendData:[
@"Content-Type: application/octet-stream\r\n"
dataUsingEncoding:NSASCIIStringEncoding]];
[body appendData:[
@"Content-Transfer-Encoding: binary\r\n"
dataUsingEncoding:NSASCIIStringEncoding]];
[body appendData:[[NSString stringWithFormat:
@"Content-Length: %i\r\n\r\n", imageData.length]
dataUsingEncoding:NSASCIIStringEncoding]];
// add the payload
[body appendData:[NSData dataWithData:imageData]];
// tell the server the payload has ended
[body appendData:
[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary]
dataUsingEncoding:NSASCIIStringEncoding]];
// add the POST data as the request body
[request setHTTPMethod:@"POST"];
[request setHTTPBody:body];
// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@", returnString);
}
몇 가지 문제가 있습니다.
PHP에서는 $ _REQUEST [ 'title'] 및 $ _FILES [ 'picture']가 설정되어 있어야합니다.
이것은 잘 쓰여진 질문이지만 "ios"또는 "objective-c"태그가 지정되지 않았기 때문에 오랜 시간 동안 답변을 얻지 못했을 것입니다. 그 태그를 추가 할 수 있습니까? 아직 수행 할 수있는 권한이 없기 때문입니다. –