zoukankan      html  css  js  c++  java
  • 微信小程序单个上传 多个上传

    单个上传

      //选择图片
      uploadImg() {
        const that = this;
        wx.chooseMessageFile({
          count: 1,
          type: 'image',
          success(res) {
            // tempFilePath可以作为img标签的src属性显示图片
            const tempFilePaths = res.tempFiles;
            wx.uploadFile({
              url: interfaces.uploadeImg,
              filePath: tempFilePaths[0]['path'],
              name: 'file',
              formData: {
                'user': 'test'
              },
              success(res) {
                let data = JSON.parse(res.data);
                console.log(data)
                if (data.code == 200) {
                  that.setData({
                    uuid: data.data.uuid,
                    icon: data.data.link
                  })
                }
              }
            })
          }
        })
      },
    View Code

    多个上传

      uploadpicture() {
        const that = this;
        let images = that.data.images;
        wx.chooseMessageFile({
          count: 6,
          type: 'image',
          success(res) {
            console.log(res.tempFiles)
            // tempFilePath可以作为img标签的src属性显示图片
            let tempImages = res.tempFiles;
            if (tempImages.length > 6) {
              wx.showToast({
                title: "最多只能上传6张",
                icon: 'none'
              })
              return;
            }
            for (let i = 0; i < tempImages.length; i++) {
              wx.uploadFile({
                url: interfaces.uploadeImg,
                filePath: tempImages[i].path,
                name: 'file',
                formData: {
                  'user': 'test'
                },
                success: (res) => {
                  let data = JSON.parse(res.data);
                  if (data.code == 200) {
                    images += "," + data.data.uuid;
                    if (images[0] === ',') {
                      images = images.substring(1);
                    }
                    that.setData({
                      images
                    }, () => {
                      wx.showLoading({
                        title: '上传成功',
                        duration: 1000
                      })
                    })
                  }
                },
                fail: (res) => {
                  console.log(res)
                  wx.showToast({
                    icon: "none",
                    title: '上传图片失败,服务器异常',
                    duration: 2000
                  })
                }
              })
            }
          }
        })
      },
    View Code
  • 相关阅读:
    随机数生成器
    赌博的艺术
    基本算法——包罗万象
    对于搜索的新理解
    关于动态规格的新理解
    发现的好东西——bitset
    高精度(重定义版)——来自
    ac自动机(模板)
    数据采集框架Gobblin简介
    Hadoop的数据采集框架
  • 原文地址:https://www.cnblogs.com/lvlisn/p/15715612.html
Copyright © 2011-2022 走看看