У меня проблема с загрузкой видео в мое приложение.Я вижу видео в разделе «Мои видео на YouTube», но затем появляется сообщение «невозможно преобразовать видеофайл».Я успешно загрузил это видео через загрузчик YouTube.Скажите, пожалуйста, что не так с моим кодом и что означает ошибка.
Код здесь:
-(NSString*) GetHeader{
NSString* xml = [[NSString alloc] init];
xml = [xml stringByAppendingString:[NSString stringWithFormat:@"%@
%@Content-Type: application/atom+xml; charset=UTF-8%@%@",kboundary,
klineTerm, klineTerm, klineTerm]];
xml = [xml stringByAppendingString:@"<?xml version=\"1.0\"?>"];
xml = [xml stringByAppendingString:@"<entry xmlns=\"http://www.w3.org/
2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt=
\"http://gdata.youtube.com/schemas/2007\"> <media:group><media:title
type=\"plain\">Movie.m4v</media:title><media:description type=\"plain
\">I gave a bad toast at my friends wedding.</
media:description><media:category scheme=\"http://gdata.youtube.com/
schemas/2007/categories.cat\">People</
media:category><media:keywords>toast, wedding</media:keywords></
media:group></entry>\r\n"];
xml=[xml stringByAppendingString:[NSString stringWithFormat:@"%@
%@Content-Type: video/m4v%@Content-Transfer-Encoding: binary%@
%@",kboundary,klineTerm,klineTerm,klineTerm,klineTerm]];
return xml;
}
-(IBAction)uploadVideoByAuthKey:(id)respons{
NSMutableData* requestBody;
const char *utfMyString = [[self GetHeader] UTF8String];
const char *utfMyString1=[[NSString stringWithFormat:@"%@
%@--",klineTerm,kboundary] UTF8String];
requestBody=[NSMutableData dataWithBytes:utfMyString
length:strlen(utfMyString)+1];
//Add video file in body
NSURL* URL = [[NSBundle mainBundle] URLForResource:@"Movie"
withExtension:@"m4v"];
NSData*file=[NSData dataWithContentsOfURL:URL];
[requestBody appendData:file];
[requestBody appendData:[NSData dataWithBytes:utfMyString1
length:strlen(utfMyString1)+1]];
//Create request
NSMutableURLRequest* request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:kVideoRequestURL]];
[request setHTTPMethod:@"POST"];
[request addValue:[NSString stringWithFormat:@"multipart/related;
boundary=%@;",kboundaryheader] forHTTPHeaderField:@"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%i",[requestBody
length]] forHTTPHeaderField:@"Content-Length"];
[request addValue:[NSString stringWithFormat:@"GoogleLogin auth=
%@",authKey] forHTTPHeaderField:@"Authorization"];
[request addValue:[NSString stringWithFormat:@"key=%@",kdevKey]
forHTTPHeaderField:@"X-GData-Key"];
[request addValue:[NSString stringWithFormat:@"%@",@"Movie.m4v"]
forHTTPHeaderField:@"Slug"];
[request addValue:@"add_video_to_youtube" forHTTPHeaderField:@"X-
GData-Client" ];
[request setHTTPBody: requestBody];
}