【问题标题】:How can I unzip the zipped file using AngularJs?如何使用 AngularJs 解压缩压缩文件?
【发布时间】:2019-06-05 00:12:47
【问题描述】:

我想在使用 AngularJS 下载文件时解压缩压缩文件。

我正在尝试使用以下代码,

例如:

<a download="My_File.PNG" target="_self" ng-href="Path of the zip file/My_File.PNG.zip">My_File.PNG</a>

如何在浏览器中从My_File.PNG.zip 下载实际文件My_File.PNG

【问题讨论】:

    标签: javascript html angularjs angularjs-directive


    【解决方案1】:

    您不能直接从 Angular 执行此操作,但您可以调用使用 JSUnzip 库,您可以从 Angular 控制器 https://github.com/augustl/js-unzip 调用该库

         var myZip = ... // Get it with an XHR request, HTML5 files, etc.
         var unzipper = new JSUnzip(myZip);
         unzipper.isZipFile();      // true or false
    
         unzipper.readEntries();    // Creates "entries"
         unzipper.entries;          // Array of JSUnzip.ZipEntry objects.
    

    【讨论】:

    • 不工作,尝试打开文件时出现大问题,错误通常是 this.stream.charCodeAt is not a function JSUnzip.BigEndianBinaryStream.prototype.getByteAt@../js/js-unzip.js:102 js-unzip.js 第 102 行`getByteAt: function (index) { return this.stream.charCodeAt (指数); // return this.stream.charCodeAt(index) & 0xff;//我在网上找到的补丁,也没有用 }` .
    【解决方案2】:

    有点晚了,但问题出在角度请求上。您必须传递一个特殊参数,如
    $http.get('...', { responseType: "arraybuffer" }).success(successfunc);
    然后继续解压缩。搜索这个...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-27
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      相关资源
      最近更新 更多