当前位置:网站首页>uniapp中调用相机相册/上传/扫码整理
uniapp中调用相机相册/上传/扫码整理
2022-07-20 13:27:00 【潘潘同学】
调用相机相册
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['camera','album'], //这要注意,camera掉拍照,album是打开手机相册
success: (res)=> {
console.log(res);
const tempFilePaths = res.tempFilePaths;
}
});
这个api调完之后,会返还一个数组,带着照片的信息
随后就可以调用上传API
uni.uploadFile({
url: 'https://www.cailanzi001.com/api/v1/qiniu/upload/img', //服务器地址
fileType:"image",//ZFB必填,不然报错
filePath: tempFilePaths[0],//这个就是我们上面拍照返回或者先中照片返回的数组
name: 'imgFile',
success: (uploadFileRes) => {
let imgData = JSON.parse(uploadFileRes.data)
console.log(imgData.data.imgUrl);
console.log(this);
this.imgDataUrl = imgData.data.imgUrl
}
});
调用上传接口,把我们拍的照片,或者手机相册选择的相册发送给对应的服务器,然后服务器会返回一个在线的图片地址给我,在html中写一个img标签 把url写给对应的src即可
扫码
uni.scanCode({
onlyFromCamera: true,//只允许拍照,不允许本地相册
scanType:["qrCode"],//扫码类型 以为 二位 xxx
success: (res)=> {
console.log('条码内容:' + res);
}
});
边栏推荐
- Hj76 nikochus theorem
- Looking back from the eight queens problem (violent enumeration)
- Control the operation of the test module through the panel in canoe (Advanced)
- 四.uni-app组件[视图组件、基本内容(官方自带例如表单类)、UI组件库、组件库的坑]
- MySQL Basics (functions and constraints)
- How to write the docker cleaning cache script
- Safety day 3 after class practice
- The electricity load of many provinces has reached a record high, and efforts have been made to ensure the safety of energy supply in summer
- 如何关闭页面之前清空LocalStorage
- Chapter3 : Fighting COVID-19 with Artificial Intelligence
猜你喜欢
行业现状令人失望,工作之后我又回到UC伯克利读博了
Roommate transferred to software testing, with a monthly salary of 14000, fishing every day and nothing to do
CANoe不能自动识别串口号?那就封装个DLL让它必须行
Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
[freeswitch development practice] using ESL to connect freeswitch in C language
芯片卖到沙子价:雷军的梦想,让这家公司「糟蹋了」
AMD EPYC 9654 Genoa CPU缓存测试曝光 L1带宽高达30TB/s
六.uniapp[闪屏页加载方式、闪屏页设置]
十年烧光1300亿,垂直电商终将走进历史尘埃
Several silly built-in functions about relative path / absolute path operation in CAPL script
随机推荐
Android Kotlin使用ARouter组件化路由及DataStore替代SharedPreferences保存数据
[upload range 17-21] secondary rendering, conditional competition, black and white list bypass
Control the operation of the test module through the panel in canoe (Advanced)
Safety day 3 after class practice
Yu Meimei, Ji Gongdu
PHP渗透测试文件包含漏洞与利用的方法
FreeRTOS个人笔记-FreeRTOSConfig.h
Arrow 之 builder
这款IDE插件3.0让你成为公司最懂安全的程序员
The fathers of programming languages are too bored to retire and choose to return to the workplace
Leetcode 322 coin change, the minimum number of change
Distributed transaction
Redis - 管理工具 redis-cli 详解
三维点云课程(五)——深度学习
Sorting and retrieval (merging / quick sorting / bisection)
JS common replace () method cases
芯片卖到沙子价:雷军的梦想,让这家公司「糟蹋了」
js 判断对象中的每个键是否有值
【微信小程序】picker-view嵌入页面的滚动选择器(84/100)
Hj14 string sorting