const filePath = "temp-file-to-upload" // 本地文件路径cos.putObject({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',Body: fs.createReadStream(filePath), // 上传文件对象onProgress: function(progressData) {console.log(JSON.stringify(progressData));},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);});
cos.request({Bucket: config.Bucket,Region: config.Region,Key: 'exampleobject',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);});
cos.getObject({Bucket: 'examplebucket-1250000000',Region: 'COS_REGION',Key: 'exampleobject',QueryString: `imageMogr2/thumbnail/200x/`,}, function (err, data) {console.log(err || data);fs.writeFileSync('filepath', data.Body); // 将图片内容保存本地});
// 生成带图片处理参数的文件签名 URL,过期时间设置为 30 分钟。var url1 = 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,不带签名。var url2 = 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);}});
本页内容是否解决了您的问题?