0

i download a zip file from web server and store on a specific location. is it possible after downloading user can see that downloaded file ? i mean how user know where file is stored so instead of searching by user i want to open that folder for user...and if this possible then how?

thank you in advance

Pooja
  • 2,162
  • 5
  • 33
  • 64

2 Answers2

2

Are you downloading the zip file within the app and storing it somewhere?

Vaibhav Tekam
  • 2,344
  • 3
  • 18
  • 27
  • If you are getting the data in NSData object, you can use its 'writeToFile:... method to save it in a file. And then you can use that file any point of time in the application. – Vaibhav Tekam Feb 24 '11 at 10:56
  • I ama using writeData, paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); self.documentsDir = [[pathsobjectAtIndex:0]stringByAppendingPathComponent:@"NewResult.zip" ]; [[NSFileManager defaultManager] createFileAtPath:documentsDir contents:nil attributes:nil]; NSFileHandle *file1 = [NSFileHandle fileHandleForUpdatingAtPath: documentsDir]; [file1 writeData: webData]; – Pooja Feb 24 '11 at 11:03
  • Then where are you getting stuck at? You can use the same path to open it again. – Vaibhav Tekam Feb 24 '11 at 11:07
  • i am writing above code in -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data--method – Pooja Feb 24 '11 at 11:07
  • 2
    NSURLConnection will download the data in chunks, you will need append the data during download. Check if you are done downloading the whole file when didReceiveData gets called first time. If not, you need append the data, and once you are done downloading the whole file( See delegate methods ), you can save the file using [data writeToPath:path atomically:NO]; Do get the file again, you will need to the path and then open it. – Vaibhav Tekam Feb 24 '11 at 11:15
  • i checked file is downloading completely but its store somewhere "/Users/Mainuser/Library/Application Support/iPhone Simulator/4.1/Applications/2zzzzz-323w-dw-e-3-434/Documents/" – Pooja Feb 24 '11 at 11:43
  • i am confuse how it will store on iphone device....right now i dont have real device so not able to debug on that.. so please help me if you have an idea thank you – Pooja Feb 24 '11 at 11:44
  • The file is getting stored in your application's grain from the SandBox of iPhone. The '/Users/Mainuser/Library/Application Support/iPhone Simulator/4.1/Applications/' being Sandbox of iPhone and '/Users/Mainuser/Library/Application Support/iPhone Simulator/4.1/Applications/2zzzzz-323w-dw-e-3-434/' being grain of your application. There is no way any other user/process/app can access this location apart from ur own application. – Vaibhav Tekam Feb 24 '11 at 11:51
2

@pooja i had worked on the same situation....in my case i was downloading the zip file from web server and i was saving that file to the documentsDirectory itself.Now as you are saying that how will user came to know that the file is downloaded or not. Then in this case i would suggest you or what i had done was.....

//Your request
        ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
    [request setDelegate:self];
    [request setDownloadDestinationPath://Your path here];
    [request setDidFailSelector:@selector(zipFileDownloadFailed:)];
    [request setDidFinishSelector:@selector(zipFileDownloaded:)];

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

UIAlertView *Downloaded = [[UIAlertView alloc] initWithTitle: @"Successfully Downloaded" message: @"" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
        [Downloaded show];
        [Downloaded release];
        Downloaded = nil;

}

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

    UIAlertView *DownloadFailed = [[UIAlertView alloc] initWithTitle: @"Download Failed" message: @"" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
    [DownloadFailed show];
    [DownloadFailed release];
    DownloadFailed = nil;
}

Now this alert will conform the user that the file is successfully downloaded or not....Now use this file wherever you want in your app...user is now conformed that the file is downloaded or not ......no need to show that to him at that place where you are downloading the file that will be something which will be so complicated.

Edited my code as per your last comment : Yes you have to unzip that file whose zip file you had downloaded within your application only..How will user unzip that file .....you have to unzip that file programatically and you have to show the contents of that file in your application.....Look there is a predefined API to zip and unzip files so try doing some searches and unzip your file in your application....

Also have a look on iPhone Unzip code as asked earliar and also download the ziparchive from here......i had taken help from all of them.

Hope you got my point and this answer will be useful to you. Good Luck!

Community
  • 1
  • 1
Sudhanshu
  • 3,950
  • 1
  • 19
  • 18
  • thank you very much for your quick reply..i am using NSMutableURLRequest should i have to change to ASIHTTPRequest or we can also do with NSMutableURLRequest thank you – Pooja Feb 24 '11 at 11:20
  • You can change if you want but no need to change your code pooja i had just shown you the example case....you do the same thing in with NSMutableURLRequest with connectionDidFinishLoading show first alert and in didFailWithError second alert – Sudhanshu Feb 24 '11 at 11:42
  • yeah update your code with these alerts and you will be able to know that the file is downloaded or not – Sudhanshu Feb 24 '11 at 11:58
  • John, i want to ask you one more thing after downloading file from web server how user will open that file...i mean you are opening this for user or user will do himself...?for example on mac if user download something mac OS will unzip it and user have to go to DOWNLOAD folder and then open that file and on windows side, after downloading file, user have to right click on download window and click on open containing folder ... i am wondering how it will be done on iphone side on real iphone device thank you – Pooja Feb 24 '11 at 12:13
  • @pooja i had updated my code as per your question try taking help from zip and unzip API. – Sudhanshu Feb 24 '11 at 12:48