微信小程序对文件和文档的操作


微信小程序对文件和文档的操作

效果展示

wxml

<camera class="camera" device-position="back" flash="false"></camera>
<button type="primary" bindtap="shoot">拍照</button>
<button bindtap="save">保存</button>
<button bindtap="savedList">文件列表</button>
<button bindtap="fileInfo">文件信息</button>

js

下面是js中除了生命周期函数之外的部分

var savedList=[];
Page({
  /**
   * 页面的初始数据
   */
  data:{
    tempFile:''
  },
  shoot:function(){
    var camera=wx.createCameraContext();
    var that=this;
    camera.takePhoto({
      quality:"high",
      success(res){
        that.setData({
          tempFile:res.tempImagePath
        })
        console.log(that.data.tempFile);
        wx.getFileInfo({
          filePath: that.data.tempFile,
          success(res){
            console.log(res);
          }
        })
      }
    });
  },
  /*缓存中一定要有文件*/
  save:function(){
    var that=this;
    wx.saveFile({
      tempFilePath: that.data.tempFile,
      success(res){
        console.log(res);
      },
      fail(res){
        console.log(res);
      }
    })
  },
  savedList:function(){
    wx.getSavedFileList({
      success: (result) => {
        console.log(result.fileList);
        savedList=result.fileList;
      },
    })
  },
  fileInfo:function(){
    wx.getSavedFileInfo({
      filePath: savedList[0].filePath,
      success(res){
        console.log(res);
      }
    });
  },
})

wxss

.camera{
    width: 100%;
    height: 600rpx;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM