美文网首页
小程序选择相册后转为base64编码的方法

小程序选择相册后转为base64编码的方法

作者: 丶卟將就 | 来源:发表于2018-07-10 17:42 被阅读127次

    wx.chooseImage({

        sizeType: ['original', 'compressed'],

        sourceType: ['album', 'camera'],

        success: function (res) {

          var tempFilePaths = res.tempFilePaths

          wx.request({

            url: tempFilePaths[0],

            method: 'GET',

            responseType: 'arraybuffer',

            success: function (res) {

              var base64 = wx.arrayBufferToBase64(res.data);

              root.setData({

                url: 'data:image/jpg;base64,' + base64

              })

            }

          });

        }

      })

    直接用就可以

    相关文章

      网友评论

          本文标题:小程序选择相册后转为base64编码的方法

          本文链接:https://www.haomeiwen.com/subject/yudqpftx.html