To publish a file until a specific time, use the publishBodyExpires(at:_:)
method as shown in the following sample code. This code publishes a file until December 31, 2099. Specify a time with the NSDateComponents
class.
Swift:
// Assume that the KiiObject "object" has been instantiated.
// Set the expiration time of the URL.
var components = DateComponents ()
components . year = 2099
components . month = 12
components . day = 31
components . hour = 23
components . minute = 59
components . second = 59
( components as NSDateComponents ) . calendar = Calendar . current
let date = ( components as NSDateComponents ) . date !
do {
// Publish the KiiObject.
let url = try object !. publishBodySynchronousExpires ( at : date )
} catch ( let error as NSError ){
// Handle the error.
return
}
// Assume that the KiiObject "object" has been instantiated.
// Set the expiration time of the URL.
var components = DateComponents ()
components . year = 2099
components . month = 12
components . day = 31
components . hour = 23
components . minute = 59
components . second = 59
( components as NSDateComponents ) . calendar = Calendar . current
let date = ( components as NSDateComponents ) . date !
// Publish the KiiObject.
object !. publishBodyExpires ( at : date ) { ( 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 expiration time of the URL.
NSDateComponents * components = [[ NSDateComponents alloc ] init ];
[ components setYear : 2099 ];
[ components setMonth : 12 ];
[ components setDay : 31 ];
[ components setHour : 23 ];
[ components setMinute : 59 ];
[ components setSecond : 59 ];
[ components setCalendar :[ NSCalendar currentCalendar ]];
NSDate * date = [ components date ];
NSError * error = nil ;
// Publish the KiiObject.
NSString * url = [ object publishBodySynchronousExpiresAt : date andError : & error ];
if ( error != nil ) {
// Handle the error.
return ;
}
// Assume that the KiiObject "object" has been instantiated.
// Set the expiration time of the URL.
NSDateComponents * components = [[ NSDateComponents alloc ] init ];
[ components setYear : 2099 ];
[ components setMonth : 12 ];
[ components setDay : 31 ];
[ components setHour : 23 ];
[ components setMinute : 59 ];
[ components setSecond : 59 ];
[ components setCalendar :[ NSCalendar currentCalendar ]];
NSDate * date = [ components date ];
// Publish the KiiObject.
[ object publishBodyExpiresAt : date
withBlock : ^ ( KiiObject * obj , NSString * url , NSError * error ) {
if ( error != nil ) {
// Handle the error.
return ;
}
}];
The basic steps are as follows:
Upload the file as an object body.
Publish the file with the publishBodyExpires(at:_:)
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.