我想创建一个包含多个图像的zip文件,然后获取整个zip文件并发送到sftp服务器

时间:2017-04-06 19:14:08

标签: objective-c zip nsfilemanager nsdocumentdirectory ssziparchive

我正在尝试从NSdcomentDirectory中的另一个目录的内容创建一个zip文件。我正在使用“SSZipArchive”。但是当我试图让zip文件不可用时。这是我正在尝试的代码。

`

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

`

我有以下问题:

  1. 如何将源目录内容作为zip文件获取。
  2. 如何获取整个zip文件,以便我可以将其作为zip发送到服务器。
  3. 请帮助我,我很长时间都在尝试。

0 个答案:

没有答案