Publishing a File for a Specific Period

To publish a file for a specific period, use the publishBodyExpires(in:_:) method as shown in the following sample code. This code publishes a file for one hour from now. Specify a period in seconds.

Swift:

  • // Assume that the KiiObject "object" has been instantiated.
    
    do{
      // Set the lifetime of the URL in seconds.
      let time : UInt = 60 * 60
    
      // Publish the KiiObject.
      let url = try object!.publishBodySynchronousExpires(in: time)
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • // Assume that the KiiObject "object" has been instantiated.
    
    // Set the lifetime of the URL in seconds.
    let time : UInt = 60 * 60
    
    // Publish the KiiObject.
    object!.publishBodyExpires(in: time){ (object : KiiObject , url : String?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • // Assume that the KiiObject "object" has been instantiated.
    
    // Set the lifetime of the URL in seconds.
    NSUInteger time = 60 * 60;
    
    NSError *error = nil;
    
    // Publish the KiiObject.
    NSString *url = [object publishBodySynchronousExpiresIn:time andError:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Assume that the KiiObject "object" has been instantiated.
    
    // Set the lifetime of the URL in seconds.
    NSUInteger time = 60 * 60;
    
    // Publish the KiiObject.
    [object publishBodyExpiresIn:time
                       withBlock:^(KiiObject *obj, NSString *url, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

The basic steps are as follows:

  1. Upload the file as an object body.
  2. Publish the file with the publishBodyExpires(in:_:) method.

Note that a user needs to be permitted the KiiACLObjectActionRead 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.