网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序之文件類API

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

一.小知識

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

 

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):獲取本地已保存的文件列表

 

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


 

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

 

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

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

 

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):新開頁面打開文檔,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx

 

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


 

二.列子

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

 

<view class="container">
	<button type="primary" bindtap="upload">上傳文件</button>
	<text>文件的路徑:{{ path}}px</text>
	<text>文件大小:{{filesize}}</text>
</view>

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

 

 

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

 

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

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

 

 

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

 


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/18170.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×