微信小程序筆記(4上傳下載文件)

這裏只是小編的一些筆記

js文件

wenjian(){
  wx.chooseMessageFile({
    count: 10,
    type: 'all',
    success (res) {
      // tempFilePath可以作爲img標籤的src屬性顯示圖片
      const tempFilePaths = res.tempFiles;
      console.log("xuanzechenggong",res);
      wx.cloud.uploadFile({
        cloudPath:new Date().getTime()+'.docx', // 上傳至雲端的路徑
        filePath: res.tempFiles[0].path, // 小程序臨時文件路徑
        success: res => {
          // 返回文件 ID
          console.log("up docx success",res);
        }, 
        fail: console.error
      })

    }
  })
},
xiazai(){//下載文建
  wx.cloud.downloadFile({
    fileID: 'cloud://yunkaifa-9btjf.7975-yunkaifa-9btjf-1301937239/1589009498782.docx',
    success: res => {
      // get temp file path
      console.log("down success",res.tempFilePath);
      wx.openDocument({
        filePath:res.tempFilePath,
        success: function (res) {
          console.log('打開文檔成功')
        }
      })
    },
    fail: err => {
      // handle error
    }
  })
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章