zoukankan      html  css  js  c++  java
  • angular1 打开文件 并另存为(文件的读取与写入)

    最近有个需求,在页面上有个按钮可以选取文件然后在导出到其它地方,

    说明白点就是文件的读取与写入,下面是例子(例子中用到了fileSave.js github地址:https://github.com/eligrey/FileSaver.js)

    首先引入fileSave.js   

    import '~/lib/file-saver/dist/FileSaver.min.js';

    html:

    <input type="file" id="fileUpload" value="选择文件" mce_style="display:none" onchange="angular.element(this).scope().fileChoose(this)" >
    <button ng-click="chaunshu()" class="btn btn-default">转移</button>

    script:

    $scope.fileChoose = (ele) => {
    $scope.files = ele.files[0];//读取文件信息
    };
    $scope.chaunshu = () => {
    if($scope.files == '' || $scope.files == undefined ){
    layer.alert('请先选择文件', {closeBtn: false, icon: 2}, index => {
    layer.close(index);
    });

    }else {
    let filename = $scope.files.name;
    let type = $scope.files.type;
    let blob = new Blob([$scope.files], {type: type}); //[$scope.files]要保存的文件 {type:保存文件类型}
    saveAs(blob, filename);//保存
    }
  • 相关阅读:
    Domain Model
    linux 后台运行命令
    morphia(3)-查询
    [八省联考2018] 劈配
    [BZOJ 3218] a+b Problem
    [学习笔记] KM算法
    [HNOI2013] 消毒
    [HNOI2014] 画框
    [HDU 6057] Kanade's convolution
    [模板] 任意模数多项式乘法
  • 原文地址:https://www.cnblogs.com/jeremy-o/p/9921696.html
Copyright © 2011-2022 走看看