Skip to content

Commit

Permalink
Merge pull request #134 from juvenn/file-callback
Browse files Browse the repository at this point in the history
Invoke fileCallback after file uploaded (or failed so)
  • Loading branch information
weakish authored Apr 20, 2020
2 parents 4b3a050 + 88ba284 commit b0a82a0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/LeanCloud/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,23 @@ public function save() {
$resp["token"] = null;
}

$callbackParams = array("token" => $resp["token"]);
try {
$uploader = SimpleUploader::createUploader($resp["provider"]);
$uploader->initialize($resp["upload_url"], $resp["token"]);
$uploader->upload($this->_source, $this->getMimeType(), $key);
$callbackParams["result"] = true;
} catch (\Exception $ex) {
$this->destroy();
$callbackParams["result"] = false;
throw $ex;
} finally {
try {
Client::post("/fileCallback", $callbackParams);
} catch (\Exception $ex) {
error_log("Request /fileCallback failed.");
}
}

forEach(array("upload_url", "token") as $k) {
if (isset($resp[$k])) {
unset($resp[$k]);
Expand Down Expand Up @@ -440,4 +449,3 @@ public function encode() {
);
}
}

0 comments on commit b0a82a0

Please sign in to comment.