0
我想弄清楚如何更新我的UIProgressView
,而我上传视频到我的服务器。视频是用户挑选视频,在这里是我的代码上传到我的服务器:更新UIProgressView,同时发布视频到php
NSMutableArray *array = [[NSMutableArray alloc]initWithContentsOfFile:[self saveUserLogin]];
int test;
NSString *string = [array objectAtIndex:3];
test = [string intValue];
test++;
NSData *videoData = fileData;
NSString *urlString = [[NSString alloc]initWithFormat:@"http://www.site.com/members/uploadMovie.php?&username=%@", [array objectAtIndex:0]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *postName = [[NSString alloc]initWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"vid%i.mov\"\r\n", test];
[body appendData:[[NSString stringWithString:postName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:videoData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@", returnString);
NSArray *values = [[NSArray alloc] initWithObjects: [array objectAtIndex:0],[array objectAtIndex:1], [array objectAtIndex:2], [NSString stringWithFormat:@"%i", test], nil];
[values writeToFile:[self saveUserLogin] atomically:YES];
[self.delegate didFinishController:self];
我UIProgressView
被命名为ProgressForUpload
,我猜,我将不得不使用一个新的线程。这个程序我也做上传图片,我能够通过这样来更新的图像:
int copy = ForProgress;
ForProgress = 100/ForProgress;
NSString *togetridof = [[NSString alloc]initWithFormat:@"%f", ForProgress];
NSString *stringWithoutdot = [togetridof stringByReplacingOccurrencesOfString:@"." withString:@""];
if(copy > 1 && copy < 11){
progressString = [[NSString alloc]initWithFormat:@"0.%@", stringWithoutdot];
}
if (copy > 10) {
progressString = [[NSString alloc]initWithFormat:@"0.0%@", stringWithoutdot];
}
if(ForProgress == 100){
progressString = [[NSString alloc]initWithFormat:@"%@", stringWithoutdot];
}
tellprogress = [progressString floatValue];
然后当我上传我创建一个新的线程,将增加告诉进步到目前的进展图像,直到完成。
我不知道这样的东西是否适用于上传视频。
谢谢,雅各布
我能举个例子吗? – Jacob
http://www.iphonedevsdk.com/forum/iphone-sdk-development/14919-how-upload-download-http-server-2.html有一些。我已经在应用程序中非正式上传,但我不重写该委托方法,因为我的应用程序不关心进度。 (大多数请求很小。) – Norman
另一个:http://mscerts.programming4.us/programming/iphone%20programming%20%20%20connecting%20to%20the%20network%20-%20getting%20data%20from%20the% 20internet.aspx – Norman