对象存储 OSS上传后回调通知
详细解答可以参考官方帮助文档客户端在上传Object时可以指定OSS服务端在处理完上传请求后,通知您的业务服务器,在该服务器确认接收了该回调后将回调的结果返回给客户端。因为加入了回调请求和响应的过程,相比简单上传,使用回调通知机制一般会导致客户端花费更多的等待时间。
具体说明参考:Callback
代码示例:
PutObjectRequest put = new PutObjectRequest(testBucket, testObject, uploadFilePath);put.setCallbackParam(new HashMapString, String>() { { put('callbackUrl', '110.75.82.106/callback'); put('callbackHost', 'oss-cn-hangzhou.aliyuncs.com'); put('callbackBodyType', 'application/json'); put('callbackBody', '{\'mimeType\':${mimeType},\'size\':${size}}'); }});OSSAsyncTask task = oss.asyncPutObject(put, new OSSCompletedCallbackPutObjectRequest, PutObjectResult>() { @Override public void onSuccess(PutObjectRequest request, PutObjectResult result) { Log.d('PutObject', 'UploadSuccess'); // 只有设置了servercallback,这个值才有数据 String serverCallbackReturnJson = result.getServerCallbackReturnBody(); Log.d('servercallback', serverCallbackReturnJson); } @Override public void onFailure(PutObjectRequest request, ClientException clientExcepion, ServiceException serviceException) { // 异常处理 }});
如果需要支持自定义参数,参考如下设置:
赞0
踩1