Skip to content

Commit

Permalink
ensure file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
maztch committed Jun 25, 2019
1 parent 0996760 commit fb7d8e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Iloveimg.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Iloveimg
// @var string|null The version of the Iloveimg API to use for requests.
public static $apiVersion = 'v1';

const VERSION = 'php.1.0.2';
const VERSION = 'php.1.1.16';

public $token = null;

Expand Down Expand Up @@ -187,6 +187,9 @@ public function sendRequest($method, $endpoint, $body = null, $start = false)
throw new AuthException($response->body->name, $response->code, null, $response);
}
if ($endpoint == 'upload') {
if(is_string($response->body)){
throw new UploadException("Upload error", $response->code, null, $response);
}
throw new UploadException($response->body->error->message, $response->code, null, $response);
} elseif ($endpoint == 'process') {
throw new ProcessException($response->body->error->message, $response->code, null, $response);
Expand Down
4 changes: 4 additions & 0 deletions src/ImageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public function addFileFromUrl($url)
*/
public function uploadFile($task, $filepath)
{
if(!file_exists($filepath)){
throw new \InvalidArgumentException('File '.$filepath.' does not exists');
}

$data = array('task' => $task, 'v' => self::VERSION);
$files = array('file' => $filepath);
$body = Request\Body::multipart($data, $files);
Expand Down

0 comments on commit fb7d8e3

Please sign in to comment.