私の iPhone アプリから、HTTP 投稿を介してサーバーに動画をアップロードしています。3 つの質問があるにもかかわらず、動画の投稿に成功しています (これを修正する必要があります)。
1.ネットワークがしばらく失われた場合、アップロードを再開するにはどうすればよいですか?
2.キューに複数のファイルをアップロードする方法
3.ユーザーがモバイルネットワーク(3G)を使用している場合、問題はありますか..現在、WiFiのみ(iPod)でテストしています
ここにファイル投稿コードを追加しています..
"UploadClass.h"
@implementation UploadClass
-(void)uploadVideoToServer:(NSDictionary *)bits file:(NSData *)file {
appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
sharedclass = [SharedClass sharedInstance];
NSString *urlString =@"http://sampleurl.com/upload_video";
NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//userid
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_id\"\r\n\r\n%@", appDelegate.userid] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//video file
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video\"; filename=\"%@\"\r\n", @"a.mov"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[NSData dataWithData:file]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];
conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data {
[webData appendData:data];
}
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error {
[webData release];
[conn release];
}
//---when the end of element is found---
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
sharedclass = [SharedClass sharedInstance];
if ([elementName isEqualToString:@"status"])
{
if([postStatus isEqualToString:@"true" ]){
appDelegate.isVideoUploading=@"NO";
[[NSNotificationCenter defaultCenter] postNotificationName:@"UPLOADFINISHED" object:@"true"];
NSLog(@"upload finished;");
sharedclass.cameraBtn=YES;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}else{
appDelegate.isVideoUploading=@"NO";
[[NSNotificationCenter defaultCenter] postNotificationName:@"UPLOADFINISHED" object:@"false"];
//show ui for daily posting failed!!!!!
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Faild" message:@"Please try after sometime !!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//[alert show];
//[alert release];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
}
}