NSURLRequest를 사용하여 iPhone에서 Rails 서버로 .zip 파일을 게시하려고합니다. 문제는 zip 파일의 콘텐츠 유형이 전송 중에 손실된다는 것입니다. 동일한 zip 파일을 웹 브라우저에서 Rails로 업로드하면 컨텐츠 유형이 보존됩니다. 이것은 내가 그것이 아이폰에서 보내는 방식과 관련이 있다고 믿게한다. 왜 이런 일이 일어날 지 아는 사람이 있습니까? 아래에 iPhone 코드를 게시했습니다.iPhone에서 Rails로 파일을 게시 할 때 콘텐츠 유형 유지
NSString * filePath = [self filePathForExportedData]; NSMutableURLRequest * theRequest = [NSMutableURLRequest requestWithURL : [NSURL URLWithString : kExportURLString] cachePolicy : NSURLRequestUseProtocolCachePolicy timeoutInterval : 20.0];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue: [NSString stringWithFormat:@"multipart/form-data; boundary=%@", BOUNDARY]
HTTPHeaderField : @ "Content-Type"]; NSMutableData * fileData = [NSMutableData dataWithContentsOfFile : filePath]; NSMutableData * postData = [NSMutableData dataWithCapacity : [fileData length] + 512]; [postData appendData : [[NSString stringWithFormat : @ "- % @ \ r \ n", 경계] dataUsingEncoding : NSUTF8StringEncoding]]; [postData appendData : [[NSString stringWithFormat : @ "콘텐츠 처리 : 양식 데이터, 이름 = \"% @ \ ", 파일 이름 = \"% @ \ "\ r \ n \ r \ n", @ "archive_file ", @"export.zip "] dataUsingEncoding : NSUTF8StringEncoding]]; [postData appendData : [[NSString stringWithFormat : @ "콘텐츠 유형 : 응용 프로그램/zip \ r \ n \ r \ n"] dataUsingEncoding : NSUTF8StringEncoding]]; [postData appendData : fileData]; [postData appendData : [[NSString stringWithFormat : @ "\ r \ n - % @ - \ r \ n", 경계] dataUsingEncoding : NSUTF8StringEncoding]]; [theRequest setHTTPBody : postData]; [self makeRequest : theRequest]; #이 요청을 보내드립니다