产品动态
产品公告
condition: {// 限制上传文件必须小于 5MB'numeric_less_than_equal': {'cos:content-length': 5 * 1024 * 1024},}
var policy = JSON.stringify({...conditions: [['content-length-range', 1, 5 * 1024 * 1024], // 可限制上传文件大小范围比如1 - 5MB],});
condition: {// 限制上传文件 content-type 必须为图片类型'string_like': {'cos:content-type': 'image/*'}}
var policy = JSON.stringify({...conditions: [// 限制上传文件 content-type 必须为图片类型['starts-with', '$Content-Type', 'image/*'],],});
/** 服务端生成上传路径示例 nodejs **/// 获取前端传进来的文件后缀 extconst ext = req.query.ext;const cosKey = generateCosKey(ext);function generateCosKey(ext) {const date = new Date();const m = date.getMonth() + 1;const ymd = `${date.getFullYear()}${m < 10 ? `0${m}` : m}${date.getDate()}`;const r = ('000000' + Math.random() * 1000000).slice(-6);const cosKey = `file/${ymd}/${ymd}_${r}${ext ? `.${ext}` : ''}`;return cosKey;};

文档反馈