This article mainly introduces the detailed information about the leancloud instance in the mini-program tutorial. here we will give an example to illustrate how to implement it and the instance code, for more information about how to implement the leancloud instance, see this article, the article is one by one. For more information, see
Applet leancloud-local image Upload
As I recently learned about applets on this site, I will record the implementation methods of the applet's local upload function. The following is the information I found online.
Upload the local image to the leancloud background.
Get local images or take photos. I wrote it in the previous blog. I won't talk about it here. my blog
Directly run the code:
1. index. js
// Index. js // Obtain the 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 source image or compressed image. Both have sourceType by default: ['alipay', 'Camera '], // you can specify whether the source is an album or a camera. Both have success: function (res) by default) {// return the local file path list of the selected image. the tempFilePath can be used as the src attribute of the img label 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 image url through file. url (). below is the url of an image after I upload it.
#
2. index. wxml
Get image
Thank you for reading this article. I hope it will help you. thank you for your support for this site!
For more details about the local image upload (leancloud) instance in the mini-program tutorial, please follow the PHP Chinese network!