一定時間だけ公開
一定時間だけ公開する場合は publishBodyExpires(_:in:)
メソッドを使います。下記は、ファイルを現時間より 1 時間の間に限定して公開したい場合のサンプルです。サンプルのように公開時間は秒で指定します。
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; } }];
基本的な手順は下記のとおりです。
- Object Body をアップロードします。
publishBodyExpires(_:in:)
メソッドを呼びファイルを公開します。
なお、ファイルを公開するユーザーはこの KiiObject に対する KiiACLObjectActionRead
アクションを許可されている必要があります(公開後の URL は、誰でも Web ブラウザから参照できます)。アクセス権限の詳細は KiiObject の ACL 設定 を参照してください。