diff --git a/demo/DownloadFile.php b/demo/DownloadFile.php index 872bbe3..f4d0c39 100644 --- a/demo/DownloadFile.php +++ b/demo/DownloadFile.php @@ -27,6 +27,10 @@ $fp2 = fopen(dirname(__FILE__). '/downloadImage.jpg', 'wb'); $api->downloadBody($obj, $fp2); echo "Download is done! Please see downloadImage.jpg\n"; + + // publish file + $url = $api->publish($obj); + echo "publish URL=". $url. "\n"; } catch (CloudException $e) { echo 'failed to call Kii API '. $e->getStatus(); diff --git a/src/ObjectAPI.php b/src/ObjectAPI.php index ca7475a..605f295 100644 --- a/src/ObjectAPI.php +++ b/src/ObjectAPI.php @@ -15,6 +15,8 @@ public function delete(KiiObject $object); public function updateBody(KiiObject $object, $contentType, $data); public function downloadBody(KiiObject $object, $fp); + + public function publish(KiiObject $object); } ?> \ No newline at end of file diff --git a/src/kii/KiiObjectAPI.php b/src/kii/KiiObjectAPI.php index e1adb3e..4bec84d 100644 --- a/src/kii/KiiObjectAPI.php +++ b/src/kii/KiiObjectAPI.php @@ -187,6 +187,27 @@ public function downloadBody(KiiObject $object, $fp) { } throw new CloudException($resp->getStatus(), $resp->getAsJson()); } + + public function publish(KiiObject $object) { + $c = $this->context; + $url = $c->getServerUrl(). + '/apps/'. $c->getAppId(). + $object->getPath(). + '/body/publish'; + + $client = $c->getNewClient(); + $client->setUrl($url); + $client->setMethod(HttpClient::HTTP_POST); + $client->setKiiHeader($c, TRUE); + $client->setContentType('application/vnd.kii.ObjectBodyPublicationRequest+json'); + + $resp = $client->sendJson(null); + if ($resp->getStatus() == 201) { + $respJson = $resp->getAsJson(); + return $respJson['url']; + } + throw new CloudException($resp->getStatus(), $resp->getAsJson()); + } } ?> \ No newline at end of file