当前位置:网站首页>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)
}
})
边栏推荐
- Difference between interface iterator and iteratable
- 【SVN】SVN是什么?怎么使用?
- Interface test API case, data and interface separation
- Unity uses mesh to realize real-time point cloud (II)
- VSCode+mingw64+cmake
- Register address name mapping
- 在EXCEL写VBA连接ORACLE并查询数据库中的内容
- shake数据库中怎么使用Mongo-shake实现MongoDB的双向同步啊?
- Final keyword
- NATAPP内网穿透
猜你喜欢
Unity uses mesh to realize real-time point cloud (I)
Using JWT to realize login function
Summary of PMP learning materials
正则匹配以XXX开头的,XXX结束的
Mysql database index study notes
ComputeShader
Huawei HCIP - datacom - Core 03 jours
答案在哪里?action config/Interceptor/class/servlet
Huawei hcip datacom core_ 03day
MongoDB怎么实现创建删除数据库、创建删除表、数据增删改查
随机推荐
在EXCEL写VBA连接ORACLE并查询数据库中的内容
【SVN】SVN是什么?怎么使用?
網易雲微信小程序
The use of recycling ideas
Self awakening from a 30-year-old female programmer
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
Jenkins automated email
SiteMesh getting started example
PMP Exam details after the release of the new exam outline
What is the value of getting a PMP certificate?
Pycharm create a new file and add author information
四、机器学习基础
华为HCIP-DATACOM-Core_03day
Information Security Experiment 3: the use of PGP email encryption software
Netease Cloud Wechat applet
Netease cloud wechat applet
Locust performance test 4 (custom load Policy)
Locust performance test 3 (high concurrency, parameter correlation, assembly point)
Regularly modify the system time of the computer
Serializer & modelserializer of DRF serialization and deserialization