2
votes

In my app, i want to download video files from server and store that file in IPhone document directory.

For downloading i am using ASIHTTPRequest library and i have downloaded the video(in KB size) and stored into Document directory.

but, when i downloading the video(in MB size) means, the request takes more time for that video downloading and there is no result( I have been waiting above 15 mins but there is no download).

I have tried the below code in my app and this is single download from the server.

- (IBAction)grabURLInBackground:(id)sender
{
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentsDirectory = [paths objectAtIndex:0];
     NSURL *url = [NSURL URLWithString:@"http://mobile.aghaven.com/Downloads/video/Movie.m4v"];

//NSString *file = [NSString stringWithFormat:@"%@/movie.mov", documentsDirectory];

     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     NSString* file = [documentsDirectory stringByAppendingPathComponent:@"Movie.m4v"];

   [request setDelegate:self];
   [request setTimeOutSeconds:60];
   [request setNumberOfTimesToRetryOnTimeout:2];
   [request setDownloadDestinationPath:file];
   [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request

 {
    [[[[UIAlertView alloc] initWithTitle:@"Message" 
                                 message:@"Success!!!" 
                                delegate:self 
                       cancelButtonTitle:@"OK" 
                       otherButtonTitles:nil] autorelease] show];
 }

this file(Movie.m4v) having 2.2 MB size and when i downloading this video from server means, there is no video downloaded.

Kindly suggest me how to download video files (in MB size) from server using ASIHTTPRequest?.

I am using XCode 4.2 with iOS 5 sdk.

If any sample code means its very helpful to me.

Thanks!!!

1
try using progress var to check when it stops downloading. and just for test purpose comment out set timeout and try again. plus try downloading Image which is more than 2 MB...TeaCupApp
Just a note, ASI is no longer being maintained. You should try to use AFNetworking instead.Jacob Relkin
Many Thanks dontCheckMyBlog, Jacob Relkin..I will look into yours suggestions..user2136

1 Answers

6
votes
 -(void)viewDidLoad 

{

    [super viewDidLoad];

     NSURL *url = [NSURL URLWithString:@"http://mobile.aghaven.com/Downloads/video/Movie.m4v"];

     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     [request setDownloadDestinationPath:@"/Users/pk/Desktop/my_file.m4v"];
     [request setDelegate:self];
     [request startAsynchronous];

}

 -(void)requestFinished:(ASIHTTPRequest *)request

{

    [[[[UIAlertView alloc] initWithTitle:@"Message" 
                                 message:@"Success!!!" 
                                delegate:self 
                       cancelButtonTitle:@"OK" 
                       otherButtonTitles:nil] autorelease] show];

}

 -(void)requestFailed:(ASIHTTPRequest *)request
{

    NSLog(@"%@",request.error);

}

you will see the file is on desktop.

Enjoy!