SSZipArchive有时会创建损坏的22字节zip文件

时间:2017-10-11 07:00:44

标签: ios objective-c amazon-s3 zip

我们正在使用 SSZipArchive 方法 createZipFileAtPath:withFilesAtPaths:来压缩单个日志文件,然后将其上传到Amazon S3。所有文件都位于我们的移动应用 NSTemporaryDirectory()中。

有时,当我将生成的zip文件从Amazon下载到我的Mac并双击它们时,我收到以下错误:

Archive Utility
Unable to expand "[file name].zip" into "[folder name]".
(Error 1 - Operation not permitted.)

发生这种情况时,我总是注意到文件大小为22个字节。这似乎太小了。当文件行为正常时,它们通常为1 MB或更多。

以下是我们应用的相关代码:

-(void) sendConsoleLog
{
    //NSError * error;
    //NSString * sTemp = [[NSString alloc] initWithContentsOfFile:[self logFilePath] encoding:NSUTF8StringEncoding error:&error];
    [SSZipArchive createZipFileAtPath:[self compressedLogFilePath] withFilesAtPaths:@[[self logFilePath]]];
    [self upload];
}

-(void) upload
{
    _sDestinationFileName = [NSString stringWithFormat:@"logs/%@.zip", [[NSUUID UUID] UUIDString]];

    AWSS3TransferUtilityUploadExpression *expression = [AWSS3TransferUtilityUploadExpression new];
    expression.progressBlock = self.progressBlock;
    [expression setValue:@"public-read" forRequestHeader:@"x-amz-acl"];

    AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];

    NSString * sFileURL = [NSString stringWithFormat:@"file://%@", [self compressedLogFilePath]];
    [[transferUtility uploadFile:[NSURL URLWithString:sFileURL]
                          bucket:S3_BUCKET_NAME
                             key:_sDestinationFileName
                     contentType:@"application/octet-stream"
                      expression:expression
                completionHander:self.completionHandler] continueWithBlock:^id(AWSTask *task) {

        if (task.error) {
            NSLog(@"cclChatSendLog continueWithBlock Error: %@", task.error);
        }
        if (task.exception) {
            NSLog(@"cclChatSendLog continueWithBlock Exception: %@", task.exception);
        }
        if (task.result) {
            AWSS3TransferUtilityUploadTask *uploadTask = task.result;
            NSUInteger iTaskID = uploadTask.taskIdentifier;
            NSLog(@"cclChatSendLog.h %lu continueWithBlock: Uploading...", (unsigned long)iTaskID);
        }
        return nil;
    }];
}

-(NSString*) logFilePath
{
    NSString *fileName =[NSString stringWithFormat:@"console%lu.log",(unsigned long)(appDelegate.hash)];
    return [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
}

-(NSString*) compressedLogFilePath
{
    return [NSString stringWithFormat:@"%@.zip", [self logFilePath]];
}

我想知道如果在[self logFilePath]中找不到文件,是否创建了22个字节的zip。有没有人遇到类似的行为?

0 个答案:

没有答案