<view><button type="primary" bindtap="button">上传时使用图片处理</button></view>
Page({button: function () {wx.chooseMessageFile({count: 10,type: 'all',success: function (res) {var file = res.tempFiles[0];wxfs.readFile({filePath: file.path,success: function (res) {cos.putObject({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: file.name,Body: res.data,Headers: {// 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩'Pic-Operations':'{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',},},(err, data) => {console.log(err || data);},);},fail: (err) => console.error(err),});},fail: (err) => console.error(err),});},});
<view><button type="primary" bindtap="button">对云上数据进行图片处理</button></view>
Page({button: function () {cos.request({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleImage',Method: 'POST',Action: 'image_process',Headers: {// 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩'Pic-Operations':'{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',},},(err, data) => {console.log(err || data);},);},});
<view><button type="primary" bindtap="button">下载时使用图片处理</button></view>
Page({button: function () {cos.getObject({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleImage',QueryString: `imageMogr2/thumbnail/200x/`,},(err, data) => {console.log(err || data);},);},});
<view><button type="primary" bindtap="sign">生成带图片处理参数的 URL,带签名</button><button type="primary" bindtap="unsign">生成带图片处理参数的 URL,不带签名</button></view>
Page({sign: function () {// 生成带图片处理参数的文件签名 URL,过期时间设置为 30 分钟。cos.getObjectUrl({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',Query: {`imageMogr2/thumbnail/200x/`: ''},Expires: 1800,Sign: true,},(err, data) => {if (data) {console.log(data.URL);}},);},unsign: function () {// 生成带图片处理参数的文件 URL,不带签名。cos.getObjectUrl({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',Query: {`imageMogr2/thumbnail/200x/`: ''},Sign: false,},(err, data) => {if (data) {console.log(data.URL);}},);},});
本页内容是否解决了您的问题?