午夜91福利视频,午夜成人在线观看,午夜在线视频免费观看,午夜福利短视频,精品午夜成人免费视频APP

小程序模板網

微信小程序之文件類API

發布時(shi)間:2017-12-15 08:59 所屬欄目:小程序開發教程

一.小知識

1.wx.saveFile(OBJECT):保存(cun)文件到本地。

 

wx.chooseImage({
  success: function(res) {
    var tempFilePaths = res.tempFilePaths
    wx.saveFile({
      tempFilePath: tempFilePaths[0],
      success: function(res) {
        var savedFilePath = res.savedFilePath
      }
    })
  }
})

 

2.wx.getSavedFileList(OBJECT):獲取本(ben)地(di)已保存(cun)的文件列表(biao)

 

wx.getSavedFileList({
  success: function(res) {
    console.log(res.fileList)
  }
})


 

3.wx.getSavedFileInfo(OBJECT):獲取(qu)本地文件的文件信息

 

wx.getSavedFileInfo({
  filePath: 'wxfile://somefile', //僅(jin)做示例用(yong),非(fei)真正的文件路徑(jing)
  success: function(res) {
    console.log(res.size)
    console.log(res.createTime)
  }
})

4.wx.removeSavedFile(OBJECT):刪(shan)除(chu)本地存儲(chu)的(de)文件

 

wx.getSavedFileList({
  success: function(res) {
    if (res.fileList.length > 0){
      wx.removeSavedFile({
        filePath: res.fileList[0].filePath,
        complete: function(res) {
          console.log(res)
        }
      })
    }
  }
})

 

5.wx.openDocument(OBJECT):新開頁面打開文檔,支(zhi)持(chi)格式:doc, xls, ppt, pdf, docx, xlsx, pptx

 

wx.downloadFile({
  url: '//example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打開文檔成功')
      }
    })
  }
})


 

二.列子

3.wx.getSavedFileInfo(OBJECT):獲取本地文件的(de)文件信息

 

<view class="container">
	<button type="primary" bindtap="upload">上傳(chuan)文(wen)件(jian)</button>
	<text>文(wen)件(jian)的路徑:{{ path}}px</text>
	<text>文(wen)件(jian)大(da)小:{{filesize}}&lt;/text>
</view>

//獲取(qu)應(ying)用實例
var app = getApp()
Page({
  	data:{
    	path:'',
    	filesize:0,
 	},
  	upload:function(){
	    var that=this
	    wx.chooseImage({
	        count: 1, 
	        sizeType: ['original', 'compressed'],// 可以指(zhi)定是原圖(tu)還是壓(ya)縮圖(tu),默(mo)認二者都有(you) 
	        sourceType: ['album', 'camera'],  // 可以指(zhi)定來源是相冊還是相機,默(mo)認二者都有(you)
	        success: function (res) {
	            var tempFilePaths = res.tempFilePaths;
	            console.log(tempFilePaths)
	            wx.getSavedFileInfo({
				  	filePath:res.tempFilePaths[0], //僅做(zuo)示例用,非真正的文(wen)件路徑
				  	success: function(res) {
				  		that.setData({
					      	filesize:res.size,
					    })
				  	}
				})
	            that.setData({
	                path:tempFilePaths
	            })  
	        }
	    })
  	}
})

 

 

5.wx.openDocument(OBJECT):打開文檔

 

<view class="container">
	<button type="primary" bindtap="upload">打(da)開文件</button>
</view>

//獲取應用(yong)實(shi)例
var app = getApp()
Page({
  	data:{
    	path:'',
 	},
  	upload:function(){
	    var that=this
	    wx.downloadFile({
		  	url: '//192.168.56.1/sino-ui/www.941in.com.hk/m.v1/o.pptx',//文(wen)件的(de)(de)在本地的(de)(de)路徑
		  	success: function (res) {
			    var filePath = res.tempFilePath
			    wx.openDocument({
			      	filePath: filePath,
			      	success: function (res) {
			        	console.log('打開文(wen)檔成功')
			      	}
			    })
		  	}
		})
  	}
})

 

 

這個文件的路徑,必須(xu)是(shi)http或是(shi)Https,不能使url: 'D:/WWW/sino-ui/www.941in.com.hk/m.v1/o.pptx',

 


易優(you)小程序(企業(ye)版(ban))+靈活api+前后代碼開源 碼云倉庫:
本文地址://www.jinyoudianli.com/wxmini/doc/course/18170.html 復制鏈接 如需定制請聯系(xi)易(yi)優客服咨詢:

工作日 8:30-12:00 14:30-18:00
周(zhou)六(liu)及部分節(jie)假日提(ti)供值班服務(wu)

易小優
轉人工 ×