게시 방법을 사용하여 이미지를 업로드하지만 다음 오류가 발생할 때마다 : 작업을 완료 할 수 없습니다. (NSURLErrorDomain 오류 -1012.)파일을 업로드하는 중 오류가 발생했습니다.
나에게 내가이 문제 :(
NSString *urlString = [NSString stringWithFormat:@"%@%@",Base_URL,URL_Upload];
NSURL* requestURL = [NSURL URLWithString:urlString];
NSString *filename = imageName;
//creating request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"POST"];
// set URL
[request setURL:requestURL];
// set Content-Type in HTTP header
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];
// post body
NSMutableData *postbody = [NSMutableData data];
NSData* imageData = UIImageJPEGRepresentation(image, 1);
if (imageData) {
[postbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString* fileData = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", filename];
NSLog(@"fileData %@",fileData);
[postbody appendData:[fileData dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:imageData];
[postbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
}
[postbody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:postbody];
// set the content-length
NSString *postLength = [NSString stringWithFormat:@"%d", [postbody length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[_connection start];
if (_connection) {
_reposnseData = [NSMutableData data];
}
[AFNetworking]를 사용하여 시도를 해결할 수있는 방법 (https://github.com을 제안하십시오/AFNetworking/AFNetworking) iOS에서 업로드 할 때 –