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
  • 相关阅读:
    PHP深度学习参考地址
    随手记两个链接,关于自适应屏幕显示的
    数据库查询,指定查询结果某列为固定值
    $('#id").load
    【转】Caused by: android.os.NetworkOnMainThreadException错误解决办法
    @Autowired注入DAO对象为NULL
    1-sqoop
    1-kylin架构
    1-kudu架构原理读写流程
    2、apache druid界面说明
  • 原文地址:https://www.cnblogs.com/lvlisn/p/15715612.html
Copyright © 2011-2022 走看看