Upload local images to leancloud background.
Get local pictures or take pictures, I wrote about it in the last blog post. I won't talk about it here. My blog
Go directly to the code:
1.index.js
//index.js //get application instance var app = getApp () const AV = require ('../../ utils / av-weapp.js'); Page({ data: { tempFilePaths: '' }, onLoad: function () { AV.init ({ appId: 'EJx0NSfY*********-gzGzoHsz', appKey: 'FBVPg5G*******T97SNQj', }); }, chooseimage: function () { var _this = this; wx.chooseImage({ count: 9, // default 9 sizeType: ['original', 'compressed'], // You can specify the original image or the compressed image, both by default sourceType: ['album', 'camera'], // You can specify whether the source is an album or a camera, both by default success: function (res) { // Returns a list of local file paths for the selected photo, tempFilePath can be used as the src attribute of the img tag to display the image _this.setData({ tempFilePaths: res.tempFilePaths }) var tempFilePath = res.tempFilePaths[0]; new AV.File ('file-name', { blob: { uri: tempFilePath, }, }).save().then( file => console.log(file.url()) ).catch(console.error); } }) } })
You can get the url of the image through file.url(), the following is the url of one of the images after I uploaded
http://ac-ejx0nsfy.clouddn.com/6a0b4c301fed32d0e2a8
If there are students who use leancloud, you can refer to it. Others can look at the documentation.
WeChat applet uploads local image files
<!--index.wxml--> <button style="margin:30rpx;" bindtap="chooseimage">获取图片</button> <image src="{{tempFilePaths }}" mode="aspecFill" style="width: 100%; height: 450rpx"/>
My blog: http://blog.csdn.net/qq_31383345