WeChat applet development from photo album to get pictures with camera photo local image upload

Today, I encountered the user avatar setting function of WeChat applets.

First above GIF:

微信小程序开发之从相册获取图片 使用相机拍照 本地图片上传

, then the code:

Small Demo, the code is very simple.

 acquire the picture     2.index.js  

// Index .js // Get application example var app = getapp () page ({data: {tempfilepaths: ‘}, online: function ()}, choage: function () {var_this = this; wx.chooseimage ({Count : 1, // Default 9 sizetype: [‘Original’, ‘compressed’], // can be specified as the original image or a compressed map, the default is SourceType: [‘album’, ‘Camera’], // The specified source is an album or a camera. The default has Success: function (res) {// Returns the local file path list of selected photos, TempFilePath can display pictures as an IMG tag _this.SetData ({TempFilePaths: RES .TempFilePaths}}}}}})

  
Here SourceType. The default is to get and use the camera from the photo album and use the camera, and the interface now select the picture, the first The latter is photographing, behind the photo album photo.

Here: Return is the picture in the local path. If you need to upload the picture to the server, you need to use another API.

Example code: 微信小程序开发之从相册获取图片 使用相机拍照 本地图片上传

wx.chooseImage ({Success: Function (res) {var tempfilepaths = res. temfilepaths wx.uploadfile ({URL: ‘HTTP : //example.weixin.qq.com/upload ‘, // is only example, non-real interface address FilePath: TempFilePath [0], Name:’ file ‘, Formdata: {‘ user ‘:’ test ‘}, Success: function (res) {var dataing = res.}}})

The above is all the contents of this article, and it is desirable to Everyone’s learning or work can bring a certain help, and I hope to support Tumi cloud!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment