oss直传和回调
来源:互联网 发布:淘宝授权书模板 编辑:程序博客网 时间:2024/05/22 06:45
服务端签名直传并设置上传回调
生成数据签名
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");//设置日期格式String dateString = df.format(new Date());// new Date()为获取当前系统时间String endpoint = ConstantsUtils.OSS_endpoint;String accessId = ConstantsUtils.OSS_accessId;String accessKey = ConstantsUtils.OSS_accessKey;String bucket = ConstantsUtils.OSS_bucket;String dir = dateString + "/";String host = "http://" + bucket + "." + endpoint;OSSClient client = new OSSClient(endpoint, accessId, accessKey);/// 由于回调函数涉及到数据库操作,因此oss调用回调函数时,需要带上改参数,简单的鉴权String calbackright = EncryptUtil.encrypt(ConstantsUtils.OSS_callback_md5 + orderid + ConstantsUtils.OSS_callback_md5,"MD5");try { long expireTime = ConstantsUtils.OSS_expireTime; long expireEndTime = System.currentTimeMillis() + expireTime * 1000; Date expiration = new Date(expireEndTime); PolicyConditions policyConds = new PolicyConditions(); policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000); policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir); String postPolicy = client.generatePostPolicy(expiration, policyConds); byte[] binaryData = postPolicy.getBytes("utf-8"); String encodedPolicy = BinaryUtil.toBase64String(binaryData); String postSignature = client.calculatePostSignature(postPolicy); Map<String, String> respMap = new LinkedHashMap<String, String>(); respMap.put("accessid", accessId); respMap.put("policy", encodedPolicy); respMap.put("signature", postSignature); //respMap.put("expire", formatISO8601Date(expiration)); respMap.put("dir", dir); respMap.put("host", host); respMap.put("expire", String.valueOf(expireEndTime / 1000)); String callback = "{\"callbackUrl\":\"" + callbackurl + "\",\"callbackBody\":\"filename=${object}&size=${size}&mimeType=${mimeType}&orderid=" + orderid + "&calbackright=" + calbackright + "\",\"callbackBodyType\":\"application/x-www-form-urlencoded\"}"; byte[] bytes = Base64.encodeBase64(callback.getBytes("utf-8")); respMap.put("callback", new String(bytes)); respMap.put("callback123", callback); return ResponseResult.ok(respMap);} catch (Exception e) { e.printStackTrace();}return ResponseResult.error("oss签名错误");
回调函数
public ResponseResult reportCallBack(String filename, String size, Long orderid) { if (filename == null || size == null || orderid == null) { return ResponseResult.error("有必填项为空"); } // 需要的操作 return this.orderService.updateByid(order);}
阅读全文
0 0
- oss直传和回调
- thinkphp OSS服务器签名直传
- 阿里云oss存储(js端签名直传)
- Html直接表单直传阿里云存储OSS示例
- 使用阿里云OSS服务器进行web签名直传
- 阿里云oss js前端获取签名直传文件
- 移动端文件直传到阿里云oss流程包括代码
- JS直传图片到阿里云oss服务器,不占用服务器带宽
- 阿里云OSS直传多文件上传遇到的问题及解决方案
- 阿里云oss对象存储 js web直传中文件重命名和文件数量限制问题的解决
- ueditor和oss使用
- OSS
- ALSA和OSS编程示例
- BSS、OSS和MSS(BOSS和MBOSS)
- 电信运营过程管理和OSS
- 什么是BSS/OSS,及区别和联系
- alsa和oss声音系统比较
- portal和oss的start.sh
- 常用的图像处理函数库
- 给输入框赋值
- 邻接表实现图结构的函数模板
- 网卡故障:弹出界面eth0: 错误:没有找到合适的设备:没有找到可用于链接System eth0 的
- UVA 10870 Recurrences(矩阵快速幂)
- oss直传和回调
- Android 数据绑定解耦DataBinding的简单使用
- Android Studio更新升级方法
- Java 快速排序
- 使用SparkSQL 分析日志中IP数、流量等数据
- 5.19 JLL--实习日志--view_availability前端和后端
- 网络编程-概念及UDP、TCP连接
- typename的作用
- Ajax固定写法