uniapp怎么获取U盘文件
时间: 2023-11-28 18:06:02 浏览: 98
优盘文件系统.pdf
1. 在manifest.json文件中添加权限:
```
"mp-weixin": {
"permission": {
"scope.userLocation": {
"desc": "获取用户地理位置"
},
"scope.writePhotosAlbum": {
"desc": "保存到相册"
},
"scope.writeVideoAlbum": {
"desc": "保存到视频"
},
"scope.record": {
"desc": "麦克风"
},
"scope.camera": {
"desc": "摄像头"
},
"scope.album": {
"desc": "相册"
},
"scope.userInfo": {
"desc": "用户信息"
},
"scope.userLocationBackground": {
"desc": "后台定位"
},
"scope.address": {
"desc": "通讯地址"
},
"scope.invoiceTitle": {
"desc": "发票抬头"
},
"scope.invoice": {
"desc": "获取发票"
},
"scope.werun": {
"desc": "微信运动步数"
},
"scope.record": {
"desc": "录音功能"
},
"scope.writeFiles": {
"desc": "文件读写"
},
"scope.file": {
"desc": "文件上传下载"
}
}
}
```
2. 使用wx.chooseMessageFile()方法选择文件:
```
wx.chooseMessageFile({
count: 1,
type: 'file',
success: function (res) {
console.log(res.tempFiles[0].path)
}
})
```
其中count表示可以选择的文件数量,type表示文件类型,success回调函数中的res.tempFiles[0].path即为所选文件的路径。
阅读全文