thibaultcha / TCBlobDownloadSwift

Powerful file downloads in Swift
http://cocoadocs.org/docsets/TCBlobDownloadSwift
MIT License
152 stars 43 forks source link

Unable to download giving file couldn't saved error #11

Open zelin opened 9 years ago

zelin commented 9 years ago

I am using following code to download a file.

-(void) downloadFileWithPath:(NSString )link name:(NSString )name { NSArray paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString documentsDirectory = [paths objectAtIndex:0]; // Fetch path for document directory NSString documentsPath = (NSMutableString )[documentsDirectory stringByAppendingPathComponent:APP_NAME]; documentsPath = [documentsPath stringByAppendingString:[NSString stringWithFormat:@"/%@", name]];

self.downloader = [self.downloadManager startDownloadWithURL:[NSURL URLWithString:link] customPath: documentsPath firstResponse:^(NSURLResponse *response)
{

} progress:^(uint64_t receivedLength, uint64_t totalLength, NSInteger remainingTime, float progress)
{
    self.mainController.progressBar.progress = progress;
    self.mainController.percentageLbl.text = [NSString stringWithFormat:@"%0.2f%% Completed", progress * 100 ];

} error:^(NSError *error)
{
    [self.mainController.indicator hide];
    [self.mainController.downloaderView setHidden:YES];
    [Utilities errorDisplay:error.localizedDescription];

} complete:^(BOOL downloadFinished, NSString *pathToFile)
{
    if (downloadFinished)
    {
        [self.mainController.downloaderView setHidden:YES];
        [Utilities alertDisplay:APP_NAME message:@"Files has been downloaded successfully"];
    }
}];

}

But i keep on getting

An error has occurred. The file '' couldnt be saved

This is a sample documentPath string /Users/Muhammad/Library/Developer/CoreSimulator/Devices/7088E29A-FA37-4945-9B81-C66C6FCC248A/data/Containers/Data/Application/9F75B2D2-6FBC-40D8-A658-AD7B16063720/Library/Caches/APP_NAME/aqeela abbas - Curriculum vitae 25-Nov-2013.pdf

Fatalityap commented 8 years ago

As I see this is Objective C code. But this is Swift library :))) Maybe you mean this (https://github.com/thibaultCha/TCBlobDownload) lib ?