After an object is uploaded, Object Storage Service (OSS) can send a callback request to the application server. To configure upload callback, you need to only add related callback parameters to the upload request that is sent to OSS. This topic describes how to configure upload callback.

Note Compared with simple upload, the upload with callback configured requires the client to wait for a longer time to process a callback request and response.
PutObjectRequest put = new PutObjectRequest(testBucket, testObject, uploadFilePath);

put.setCallbackParam(new HashMap<String, String>() {
    {
        put("callbackUrl", "192.168.10.106/callback");
        put("callbackHost", "yourCallbackHost");
        put("callbackBodyType", "application/json");
        put("callbackBody", "{\"mimeType\":${mimeType},\"size\":${size}}");
    }
});

OSSAsyncTask task = oss.asyncPutObject(put, new OSSCompletedCallback<PutObjectRequest, PutObjectResult>() {
    @Override
    public void onSuccess(PutObjectRequest request, PutObjectResult result) {
        Log.d("PutObject", "UploadSuccess");

        // Obtain the returned callback information. The callback information can be obtained only if servercallback is configured in the request. 
        String serverCallbackReturnJson = result.getServerCallbackReturnBody();

        Log.d("servercallback", serverCallbackReturnJson);
    }

    @Override
    public void onFailure(PutObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
        // Handle exceptions. 
    }
});
        

The following code provides an example on how to configure custom parameters:

put.setCallbackParam(new HashMap<String, String>() {
    {
        put("callbackUrl", "http://192.168.192.125/leibin/notify.php");
        put("callbackHost", "yourCallbackHost");
        put("callbackBodyType", "application/json");
        put("callbackBody", "{\"object\":${object},\"size\":${size},\"my_var1\":${x:var1},\"my_var2\":${x:var2}}");
    }
});

put.setCallbackVars(new HashMap<String, String>() {
    {
        put("x:var1", "value1");
        put("x:var2", "value2");
    }
});
        

For more information about upload callback, see Callback.