当前位置:网站首页>Wechat applet common collection

Wechat applet common collection

2022-07-06 20:05:00 Infatuated Arvin

Catalog

  Wechat applet gets the size of uploaded pictures

   Wechat applet base64 Bit size calculation

  Wechat applet subcontracting


  Wechat applet gets the size of uploaded pictures

wx.chooseImage({
        count: 1,
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: function (res) {
          var tempFilesSize = res.tempFiles[0].size;  // Get the size of the picture , Company B
          const tempFilePaths = res.tempFilePaths;
          console.log('size:', tempFilesSize)
          if (tempFilesSize <= 2000000) {   // Picture is less than or equal to 2M when   You can get pictures 
            // code

          } else {    // Picture larger than 2M, Pop up a prompt box 
            wx.showToast({
              title: ' Upload image cannot be larger than 2M!',  // title 
              icon: 'none'       // Icon  none Don't use icons , For details, see the official documents 
            })
          }

          
        },
        fail: function (res) {
          wx.hideLoading()
        }
      });

   Wechat applet base64 Bit size calculation

/****base64 Bit size calculation **/ 

getImgSize(str) {
    // obtain base64 Picture size , return KB Numbers 
    var str = base64url.replace('data:image/jpeg;base64,', '');// Here according to their own upload image format for the corresponding modification 
    
    var strLength = str.length;
    var fileLength = parseInt(strLength - (strLength / 8) * 2);

    //  From byte to byte KB
    var size = "";
    size = (fileLength / 1024).toFixed(2);
    
    
    
    return parseInt(size);

  },

  Wechat applet subcontracting


  "subPackages": [
    {
      "root": "A/",
      "pages": [
        "index/index",
        "form/form"
      ]
    },
    {
      "root": "B/",
      "pages": [
        "index/index",
        "form/form"
      ]
    }
  ]

Conclusion

         To be continued ...

原网站

版权声明
本文为[Infatuated Arvin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061207132325.html