problem to upload a video more then 10 MB?
I am try to upload a video of more then 10 MB, when i send it through ASIHTTPRequest then it start connection but not upload that movie to web
it could be due to a size limitation on your server side
-edit-
upload using NSURLConnection with the following request (if you are using multipart form data which is usually the case):
// some random value
NSString *boundary = @"0xKhTmLbOuNdArY---ThIs_Is_mY_BoUnDaRyY---pqo";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[request setHTTPMethod:@"POST"];
NSString *theContentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:theContentType forHTTPHeaderField:@"Content-type"];
NSData *theData = data;// here use your movie data
//adding the body:
NSMutableData *postBody = [NSMutableData data];
// data part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"content\"; filename=\"dummy%i.mp4\"\r\n",[[NSDate date]timeIntervalSince1970]] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n",contentType] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:theData];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// final boundary
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postBody];
[request setValue:param forHTTPHeaderField:@"Parameter"];
I have solve this problem with using this way, Basically error is accrue due to server upload limit
-(void)uploadeVideoClicked{
if (_picker) {
[_picker dismissModalViewControllerAnimated:NO];
[_picker.view removeFromSuperview];
[_picker release];
}
if (_popover) {
[_popover dismissPopoverAnimated:NO];
[_popover release];
}
_picker = [[[UIImagePickerController alloc] init] retain];
_picker.delegate = self;
_picker.editing = NO;
_picker.allowsEditing=NO;
_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_picker.wantsFullScreenLayout = YES;
_picker.videoQuality =UIImagePickerControllerQualityTypeLow;
_picker.mediaTypes =[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
_popover = [[[UIPopoverController alloc] initWithContentViewController:_picker] retain];
[_popover setDelegate:self];
[_popover presentPopoverFromRect:infoButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
#pragma mark -----------------------------
#pragma mark Image Picker Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"" message:@"You Select a image Please select Movie" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[myAlertView show];
[myAlertView release];
}
else if ([mediaType isEqualToString:@"public.movie"]){
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
//NSLog(@"found a video");
if (webData) {
[webData release];
webData = nil;
}
webData = [[NSMutableData alloc]initWithContentsOfURL:videoURL];
// webData = [NSData dataWithContentsOfURL:videoURL];
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
[self performSelector:@selector(uploadVideo) withObject:nil afterDelay:.001];
}
[_picker dismissModalViewControllerAnimated:YES];
[_picker.view removeFromSuperview];
[_picker release];
_picker = nil;
[_popover dismissPopoverAnimated:YES];
[_popover release];
}
-(void)uploadVideo
{
NSString *url = [NSString stringWithFormat:@"http://example.com/uploadvideoxml.php"];
networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue cancelAllOperations];
[networkQueue setShowAccurateProgress:YES];
[videoUploadProgressView setHidden:NO];
progressView.center = self.view.center;
[self.view addSubview:progressView];
[networkQueue setUploadProgressDelegate:videoUploadProgressView];
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(requestFinished:)];
[networkQueue setRequestDidFailSelector: @selector(requestFailed:)];
request= [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:url]] ;
[request setPostValue:[[mAppDelegate.userInfoArray objectAtIndex:1]valueForKey:@"user_id"] forKey:@"user_id"];
[request addRequestHeader:@"Content-Type"
value:@"multipart/form-data;boundary=---------------------------1842378953296356978857151853"];
NSDate *date1=[NSDate date];
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setDateFormat:@"hh:mm"];
NSString *valuestr = [formatter1 stringFromDate:date1];
////NSLog(@"%@",valuestr);
[formatter1 release];
NSString *moviename = [NSString stringWithFormat:@"WakeUUUP_%d_%@.mov",[videolistArray count],valuestr];
if(webData != nil){
[request setFile:webData withFileName:moviename andContentType:@"video/quicktime" forKey:@"userfile"];
}
[request setTimeOutSeconds:5000];
//NSLog(@"%@",request);
[networkQueue addOperation:request];
[networkQueue go];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[_picker dismissModalViewControllerAnimated:YES];
[_picker.view removeFromSuperview];
[_picker release];
_picker = nil;
[_popover dismissPopoverAnimated:YES];
[_popover release];
}
//for Ipad UIPopoverController if there is a cancel when the user click outside the popover
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
[_picker dismissModalViewControllerAnimated:YES];
[_picker.view removeFromSuperview];
[_picker release];
_picker = nil;
}
#pragma mark -------------------------
#pragma mark ASIHTTPREQUEST Delegate
- (void)requestFailed:(ASIHTTPRequest *)req
{
[progressView removeFromSuperview];
[videoUploadProgressView setHidden:YES];
////NSLog(@"Request failed: %@",[req error]);
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Failed to Post Item" message:[[req error] description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil, nil];
[errorAlert show];
[errorAlert release];
[networkQueue release];
[request release];
}
- (void)requestFinished:(ASIHTTPRequest *)req
{
[networkQueue release];
[request release];
[progressView removeFromSuperview];
[videoUploadProgressView setHidden:YES];
[[Parsing sharedInstance] assignSender:self];
NSMutableArray *resultArray =[[[NSMutableArray alloc]initWithArray:[[Parsing sharedInstance]startparsingforfun:[req responseData]]]autorelease];
NSLog(@"Response was: %@",resultArray);
if (spinner) {
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
spinner = nil;
}
if ([[[resultArray objectAtIndex:1]objectForKey:@"Transaction"]isEqualToString:@"uploadvideoxml"]) {
if ([[[resultArray objectAtIndex:1]objectForKey:@"success"]isEqualToString:@"true"]) {
[self viewWillAppear:YES];
}else {
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Failed to Update Profile" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil, nil];
[errorAlert show];
[errorAlert release];
}
}
}
精彩评论