<!-- html 页面 DOM 元素 --><!-- 选择要上传的文件 --><input id="fileSelector" type="file" /><!-- 点击按钮上传 --><input id="submitBtn" type="submit" />
function handleFileInUploading(file) {cos.putObject({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: file.name,Body: file,Headers: {// 通过 imageMogr2 接口使用图片缩放功能:指定图片宽度为 200,宽度等比压缩'Pic-Operations':'{"is_pic_info": 1, "rules": [{"fileid": "desample_photo.jpg", "rule": "imageMogr2/thumbnail/200x/"}]}',},},function (err, data) {console.log(err || data);},);}document.getElementById('submitBtn').onclick = function (e) {var file = document.getElementById('fileSelector').files[0];if (!file) {document.getElementById('msg').innerText = '未选择上传文件';return;}handleFileInUploading(file);};
<!-- html 页面 DOM 元素 --><!-- 点击按钮请求对云上数据进行图片处理 --><input id="submitBtn" type="submit" />
function handleFileInBucket() {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/"}]}',},},function (err, data) {console.log(err || data);},);}document.getElementById('submitBtn').onclick = function (e) {handleFileInBucket();};
<!-- html 页面 DOM 元素 --><!-- 点击按钮下载文件并在下载时使用图片处理 --><input id="submitBtn" type="submit" />
function getObject() {cos.getObject({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',QueryString: `imageMogr2/thumbnail/200x/`,},function (err, data) {console.log(err || data);},);}
// 生成带图片处理参数的文件签名 URL,过期时间设置为 30 分钟。cos.getObjectUrl({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',Query: {`imageMogr2/thumbnail/200x/`: ''},Expires: 1800,Sign: true,},function (err, data) {if (data) {console.log(data.URL);}},);// 生成带图片处理参数的文件 URL,不带签名。cos.getObjectUrl({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',Query: {`imageMogr2/thumbnail/200x/`: ''},Sign: false,},function (err, data) {if (data) {console.log(data.URL);}},);
本页内容是否解决了您的问题?