public function upload($stream, $filename = null)
{
if (!isset($this->upload->url)) {
throw new Exceptions\ApiException("Upload is not allowed in this process state", 400);
}
if (empty($filename)) {
$metadata = stream_get_meta_data($stream);
$filename = basename($metadata['uri']);
}
$this->api->put($this->upload->url . "/" . rawurlencode($filename), $stream, false);
return $this;
}