Micro letter applet cloud development (notes) ---- images to the specified folder

When you upload pictures with a small program documentation methods inside, there is a default cloud storage root directory, you want each section stored in different files within a folder, you can directly add [cloudPath], in front of the file name plus the name of the defined folders

For example: const cloudPath = 'folder name /' + file name

  ChooseImage: function() {
    var that = this
    const imgNum = 4 - that.data.swiperList.length
    // Select Image
    wx.chooseImage({
      count: imgNum,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function(res) {
        wx.showLoading({
          title: 'upload'
        })
        const filePath = res.tempFilePaths[0]
        // upload image
        var timestamp = Date.parse(new Date());
        const cloudPath = 'set_up_img/' + timestamp + filePath.match(/\.[^.]+?$/)[0]
        wx.cloud.uploadFile({
          cloudPath,
          filePath,
          success: resa => {
              that.setData({
                swiperList: that.data.swiperList.concat(resa.fileID)
              })
          },
          fail: e => {
            wx.showToast({
              icon: 'none',
              title: 'upload failed'
            })
          },
          complete: () => {
            wx.hideLoading()
          }
        })
      },
      fail: e => {
        console.error(e)
      }
    })
  },

 

Guess you like

Origin www.cnblogs.com/yeshengshudaixiong/p/11645694.html