/** * Save file on the cloud * * @throws CloudException */ public function save() { if (!$this->isDirty()) { return; } $data = array("name" => $this->getName(), "ACL" => $this->get("ACL"), "mime_type" => $this->getMimeType(), "metaData" => $this->getMeta()); if ($this->isExternal()) { $data["url"] = $this->getUrl(); $resp = LeanClient::post("/files/{$this->getName()}", $data); $this->mergeAfterSave($resp); } else { $key = static::genFileKey(); $key .= "." . pathinfo($this->getName(), PATHINFO_EXTENSION); $data["key"] = $key; $resp = LeanClient::post("/qiniu", $data); $token = $resp["token"]; unset($resp["token"]); $this->mergeAfterSave($resp); LeanClient::uploadToQiniu($token, $this->_source, $key, $this->getMimeType()); } }