Detailed description of the local image upload (leancloud) instance in the WeChat applet tutorial

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.