钉钉小程序点击上传图片

dd.chooseImage({ //请求图片

count: 1,  //上传图片张数限制 

success: (res) => {

console.log("返回的文件信息为:");

console.log(res);

var filePaths = res.filePaths;

dd.getAuthCode({

success: function(res) {

console.log('filePath的值为:');

console.log(filePaths);

var authCode = res.authCode;

dd.uploadFile({

url: app.data.globalData.url + 'public/index.php/api/activity/upload_img',

fileType: 'image',

fileName: 'img',

filePath: filePaths[0],

formData: {

authCode: authCode

},

success: (res) => {

var data = JSON.parse(res.data);

console.log("转换后的data为:");

console.log(data);

var img_url = data.data.img_url;

that.data.actImg = img_url;

that.data.isUp = 1; //同时将是否已经上传改为是

console.log('图片信息为:');

console.log(that.data.actImg);

that.setData({

coverImg: that.data.actImg,

isUp: 1

})

},

fail: function(res) {

dd.showToast({

content: '上传信息失败',

type: 'fail',

});

},

});

},

fail: function(res) {

dd.showToast({

content: '获取用户权限信息失败',

type: 'fail',

});

}

})

},

});

你可能感兴趣的:(前端)