当前位置:网站首页>Upload taro pictures to Base64
Upload taro pictures to Base64
2022-07-07 09:27:00 【-Coffee-】
It hasn't been updated for a long time csdn 了 , Shake yourself up , Keep updating taro The pit on the road of learning ....
Recently used taro Develop multi terminal applet , Front end and back end data interaction , Stepped on a lot of pits , because taro Relatively new , So many problems are difficult to find solutions from the Internet ,
now, recorded , Share with friends in need .
Cut to the chase :
The original idea of the picture is to base64 Back end processing , But look at the document Decide to use uploadFile Upload to the third-party cloud image server , Encounter various problems , Failed to succeed , Calm down and , Original intention of detection , turn base64, Back end to handle , The code is as follows
// The picture is translated into base64
imgOnChange (files) {
this.setState({
files
})
Taro.request({
url:files[0].url,
responseType: 'arraybuffer', // The most critical parameter , Set the returned data format to arraybuffer
success:res=>{
// hold arraybuffer Turn into base64
let base64 = Taro.arrayBufferToBase64(res.data);
// Without this string of characters , Cannot display
base64 = 'data:image/jpeg;base64,' + base64
// see base64 character string , You can also go to the web page to check whether it can be restored to your picture
console.log(base64)
}
})
边栏推荐
- shake数据库中怎么使用Mongo-shake实现MongoDB的双向同步啊?
- 嵌套(多级)childrn路由,query参数,命名路由,replace属性,路由的props配置,路由的params参数
- 进程间的通信方式
- Jemter operation
- What are the conditions for applying for NPDP?
- Summary of PMP learning materials
- 创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
- Variable parameter of variable length function
- How can I apply for a PMP certificate?
- 12、 Sort
猜你喜欢
软件建模与分析
STM32 clock system
Cesium load vector data
[SVN] what is SVN? How do you use it?
Where is the answer? action config/Interceptor/class/servlet
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
Huawei hcip datacom core_ 03day
Information Security Experiment 3: the use of PGP email encryption software
Locust performance test 3 (high concurrency, parameter correlation, assembly point)
Mysql:select ... for update
随机推荐
信息安全实验一:DES加密算法的实现
十二、排序
flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
Detailed learning notes of JVM memory structure (I)
Cesium does not support 4490 problem solution and cesium modified source code packaging scheme
Leetcode question brushing record (array) combination sum, combination sum II
Jenkins modifies the system time
PMP Exam Preparation experience, seek common ground while reserving differences, and successfully pass the exam
数据库多表关联查询问题
Netease cloud wechat applet
Colorbar of using vertexehelper to customize controls (II)
Information Security Experiment 1: implementation of DES encryption algorithm
Redis common commands
Mysql:select ... for update
Install pyqt5 and Matplotlib module
(3/8) method parameters of improper use of enumeration (2)
Locust performance test 4 (custom load Policy)
【SVN】SVN是什么?怎么使用?
C language pointer (Part 2)
Regular matching starts with XXX and ends with XXX