개인적인 메모겸 글 작성.
Post 방식 업로드만 몇일동안 헤매다가 어느 순간 "딱!"하고 되길래 그대로... 냉동 보관/사용중인 함수..
뭐 웹 개발자 분에 옆에 계시고 같이 하시거나, 웹/애플 같이 개발 가능하신분이라면 아래소스가 어렵지 않을듯.
-(형태없음) 나의 포스트 방식 업로드 메소드
{
NSURL *url = [NSURL URLWithString:DF_INPUTACCEPT_URL];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"AaB03x"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[self appendDataForHTTPPOST:body boundary:boundary addkey:@"Param" withValue:@"value"];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString * str = [[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"Param\"; filename=\"%@\"\r\n" ,self.paymentInfo.acc_Mento];
[body appendData:[
[str precomposedStringWithCanonicalMapping]
dataUsingEncoding:NSUTF8StringEncoding ] ];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *audioFileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"/%@", PATH]];
[body appendData:[NSData dataWithContentsOfURL:audioFileURL]];
[self appendDataForHTTPPOST:body boundary:boundary addkey:@"Param" withValue:@"value"];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
self.UploadConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
-(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{//전송 상황
float fCurrentPercent = (float)totalBytesWritten / (float)totalBytesExpectedToWrite;
float fTotalKByte = (float)totalBytesExpectedToWrite/1024.0f;
float fCurrentKByte = (float)totalBytesWritten/1024.0f;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{//응답
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{//데이터 수신
NSMutableData *receiveData;
if (receiveData == nil) {
receiveData = [[NSMutableData alloc] init];
}
[receiveData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{// 접속 실패
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{// 완료
}
Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다
당신의 의견을 작성해 주세요.