views:

70

answers:

1

Hi all,

I'm using following code to save the downloaded file to iphone/ipod-touch's documents directory.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
[receivedData writeToFile:basePath atomically:YES];

The file downloaded can be of any type which can be opened using Neooffice. The file is getting downloaded as I'm able to see a success message in console which is in connectionDidFinishLoading method along with the number of bytes received, but not getting saved at the given path.

EDIT:

It seems to be getting saved but in the form of .sqlite file which when opened is found empty. Don't know how to address this issue.

Can anybody please help?

Thanx in advance.

+1  A: 

File path must contain file name, not only the directory where file should be:

[receivedData writeToFile:[basePath stringByAppendingPathComponent:yourFileName] atomically:YES];

While downloading you can get the file name in suggestedFilename property of NSURLResponse or specify any name you want.

Vladimir
Thank you so much Vladimir, it worked.. One more question: If I'm saving a .pptx file then it's getting unarchieved into a folder containing not any .pptx file, but various .xml files. Why this is happening? Also, if I'm providing the file name where the downloaded file should be stored then next time whenever any new file will be downloaded then will the earlier be erased? Thanx.
neha
1. can't say anything about that, make sure that file you downloading is correct. 2. Yes, if you write a file then existing file with the same name will be overwritten
Vladimir