Publishing a File until a Specific Time

To publish a file until a specific time, use the publishBodyExpiresAt() method as shown in the following sample code. This code publishes a file until December 31, 2099. Specify a UNIX timestamp in milliseconds (UTC).

  • // Assume that the KiiObject "object" has been instantiated.
    
    // Set the expiration time of the URL.
    Calendar calendar = Calendar.getInstance();
    calendar.set(2099, Calendar.DECEMBER, 31, 23, 59, 59);
    long time = calendar.getTimeInMillis();
    
    try {
      // Publish the KiiObject.
      String publishUrl = object.publishBodyExpiresAt(time);
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • // Assume that the KiiObject "object" has been instantiated.
    
    // Set the expiration time of the URL.
    Calendar calendar = Calendar.getInstance();
    calendar.set(2099, Calendar.DECEMBER, 31, 23, 59, 59);
    long time = calendar.getTimeInMillis();
    
    // Publish the KiiObject.
    object.publishBodyExpiresAt(time, new KiiObjectPublishCallback() {
      @Override
      public void onPublishCompleted(String url, KiiObject object, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });

The basic steps are as follows:

  1. Upload the file as an object body.
  2. Publish the file with the publishBodyExpiresAt() method.

Note that a user needs to be permitted the READ_EXISTING_OBJECT action on a KiiObject to publish its object body (Once published, anyone can access the object body with the URL). See Setting a KiiObject's ACL for more information about the access rights.