I want to crete a zip file with multiple images in it and get the entire zip file and send to sftp server

让人想犯罪 __ 提交于 2019-12-08 14:25:59

问题


I am trying create a zip file from the contents of another directory in NSdcomentDirectory. I am using "SSZipArchive" for this. But When I try to get the zip file its not available.Here is my code which I am trying.

`

NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"/SourceFolder"];
NSString *stringPath2 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"/ZipFolder"];

//SourceFolder Creation
NSError *error = nil;
if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];


//ZipFolder Creation
if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:stringPath2 withIntermediateDirectories:NO attributes:nil error:&error];


//Adding Files To SourceFolder
NSData *data = UIImageJPEGRepresentation([UIImage imageNamed:@"flower.jpg"], 1.0);
NSData *data2 = UIImageJPEGRepresentation([UIImage imageNamed:@"Wall.jpg"], 1.0);

[data writeToFile:[stringPath stringByAppendingFormat:@"/image1.jpg"] atomically:YES];
[data2 writeToFile:[stringPath stringByAppendingFormat:@"/image2.jpg"] atomically:YES];



//Retriving Path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *sampleDataPath = [documentsDirectory stringByAppendingPathComponent:@"/SourceFolder"];
NSString *sampleDataPath2 = [documentsDirectory stringByAppendingPathComponent:@"/ZipFolder"];


//To Create ZipFile under /ZipFolder from /SourceFolder
[SSZipArchive createZipFileAtPath: sampleDataPath2 withContentsOfDirectory: sampleDataPath];

//Checking If File exist in source and zip folder
NSFileManager *sharedFileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *files = [sharedFileManager enumeratorAtPath:sampleDataPath]; // The content shows two images which I have added ->image1.jpg,image2.jpg
NSDirectoryEnumerator *files2 = [sharedFileManager enumeratorAtPath:sampleDataPath2]; // However I dont see the .zip file inside it

`

I have below questions:

  1. How can I get the source directory content as a zip file.
  2. How to get the entire zip file so that I can send it to server as zip.

Please help me I am trying from a long time.

来源:https://stackoverflow.com/questions/43263927/i-want-to-crete-a-zip-file-with-multiple-images-in-it-and-get-the-entire-zip-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!