云开发,上传文件,设置设置路经
发布于 5 年前 作者 fangpan 10154 次浏览 来自 问答

云开发,上传文件,设置设置路经

chooseOneImage(e) {

    var that =this

    wx.chooseImage({

      count: 1,

      // sizeType: ['original '], // 可以指定是原图还是压缩图,默认二者都有

      sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有

      success: function (res) {

  

        const filePath = res.tempFilePaths[0]

        console.log(filePath)

        // 上传图片

        const cloudPath = ‘my-image’ + filePath.match(/\.[^.]+?$/)[0]

        console.log(‘cloudPath>>’,cloudPath)

        wx.cloud.uploadFile({

          cloudPath,

          filePath,

          success: res => {

            console.log(’[上传文件] 成功:’, res)

            console.log(res.fileID)

            console.log(cloudPath)

            console.log(filePath)

            app.globalData.fileID = res.fileID

            app.globalData.cloudPath = cloudPath

            app.globalData.imagePath = filePath

打开相册的代码,怎么样才能上传到我指字的路经  我的环境/目录A /目录A子目录 现在网上的代码都是环境的根据下了

2 回复

const cloudPath = “myshare/BgPic/”+‘my-image’ + filePath.match(/\.[^.]+?$/)[0]

谢谢,我找也找到了,实验出来了。

回到顶部