• SharpZipLib 压缩后传输给第三方平台无法识别问题


    问题描述:在项目中需要将文件压缩然后传输给三方进行彩信发送,使用SharpZipLib 进行压缩,原先使用J#进行压缩处理,但是用SharpZipLib压缩后的zip文件传输过去之后,总会报发送失败。最后在加入 s.UseZip64 = UseZip64.Off;这一句话后,解决问题。特此记录。

    using (ZipOutputStream s = new ZipOutputStream(File.Create(argZipPath)))
                    {
                        s.UseZip64 = UseZip64.Off;
                        s.SetLevel(9); // 0 - store only to 9 - means best compression
                        byte[] buffer = new byte[4096];
                        foreach (string file in argFiles)
                        {
                            // Using GetFileName makes the result compatible with XP
                            // as the resulting path is not absolute.
                            ZipEntry entry = new ZipEntry(Path.GetFileName(file));
                            // Setup the entry data as required.
    
                            // Crc and size are handled by the library for seakable streams
                            // so no need to do them here.
                            // Could also use the last write time or similar for the file.
                            entry.DateTime = DateTime.Now;
                            s.PutNextEntry(entry);
    
                            using (FileStream fs = File.OpenRead(file))
                            {
                                int sourceBytes;
                                do
                                {
                                    sourceBytes = fs.Read(buffer, 0, buffer.Length);
                                    s.Write(buffer, 0, sourceBytes);
                                } while (sourceBytes > 0);
                            }
                        }
    
                        s.Finish();
                        s.Close();
                    }
    

      

  • 相关阅读:
    32 renren-fast-vue安装报错问题
    31 element自定义图片上传
    30 图片预览
    29 element-table样式更改
    28 ant-design-vue-jeecg运行报错问题
    27 mysql8安装
    25 mybatis-plus常用语法
    24 element表单校验
    23 鼠标移入移出更换样式
    22 初识mysql外键
  • 原文地址:https://www.cnblogs.com/gonganruyi/p/4169670.html
Copyright © 2020-2023  润新知