收藏
回答

用云调用二维码后返回res.result.buffer,用云函数上传后返回显示不出来?

1、index.js

Page({

    onLoad: function (options) {

 console.log('test')

  wx.cloud.callFunction({

    name: "yhs1",

    data: {},

    success: res =>{

      console.log('test2')

      console.log('test1',res.result.buffer)

      this.setData({

        imaget:res.result.buffer

      })

    },


    fail: err =>{

      console.log()

    }

  })

  },

  check: function () {

    var imaget=this.data.imaget

    console.log('test1',imaget)

 console.log('test')

  wx.cloud.callFunction({

    name: "yhs2",

    data: {

      demo:imaget

    },

    success: res =>{

      console.log('test2')

      console.log('test1',res.result)

      this.setData({

        imaget2:res.fiedId

      })

    },

    fail: err =>{

      console.log()

    }

  })

  }

  })

2、index.wxml

<image style="width: 200px; height: 200px; background-color: #eeeeee;" mode="{{item.mode}}" src="{{imaget2}}"></image>

  <view class="crr">

 <button class="ff" bindtap='check'>test</button>

</view>

3、云函数yhs1

// 云函数入口文件

const cloud = require('wx-server-sdk')

 cloud.init({

      env: 'testw-z6k1v'

    })

exports.main = async (event, context) => {

  try {

    const result = await cloud.openapi.wxacode.createQRCode({

        path: 'page/index/index',

        width: 430

      })

    return result

  } catch (err) {

    return err

  }

}

4、云函数yhs2

// 云函数入口文件

const cloud = require('wx-server-sdk')

 cloud.init({

      env: 'testw-z6k1v',

    })

exports.main = async (event, context) => {

  return await cloud.uploadFile({

    cloudPath: 'demo.jpg',

    fileContent: event.demo

  })

}


运行后:

{contentType: "image/jpeg", buffer: ArrayBuffer(55707), errMsg: "openapi.wxacode.createQRCode:ok", errCode: 0}buffer: ArrayBuffer(55707)[[Int8Array]]: Int8Array(55707) [-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, -1, -37, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, -1, -37, 0, 67, 1, 3, 4, 4, 5, 4, 5, …][[Uint8Array]]: Uint8Array(55707) [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, 255, 219, 0, 67, 1, 3, 4, 4, 5, 4, 5, …]byteLength: (...)__proto__: ArrayBuffercontentType: "image/jpeg"errCode: 0errMsg: "openapi.wxacode.createQRCode:ok"__proto__: Object


index.js:28 test1 {contentType: "image/jpeg", buffer: ArrayBuffer(55707), errMsg: "openapi.wxacode.createQRCode:ok", errCode: 0}




回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-06-12
    res.result.fileID
    
    代码可以合并到一起的
    
    
    

    2020-06-12
    有用 1
    回复 5
    • 相
      2020-06-13
      页面参数怎样传递?
      2020-06-13
      回复
    • 相
      2020-06-13回复
      const cloud = require(wx-server-sdk)
       cloud.init({
            
          })
      // 云函数入口文件
      exports.main = async (event, context) => {
        try {
          const result = await cloud.openapi.wxacode.createQRCode({
              path: 'page/index/index?msessage='+message,
              width: 430
            })
          const file = await cloud.uploadFile({
          cloudPath: 'demo.jpg',
          fileContent: result.buffer,
        })
          return file
        } catch (err) {
          return err
        }
      }
      2020-06-13
      回复
    • Mr.Zhao
      Mr.Zhao
      发表于小程序端
      2020-06-13回复
      event啊,传不过去?
      2020-06-13
      回复
    • 相
      2020-07-03
      2020-07-03
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-07-03回复
      全靠猜大佬   页面不存在是个啥玩意?
      2020-07-03
      回复
登录 后发表内容
问题标签