public function parseUrl($url) {
        $region = $this->getConfig('region');
        $bucket = $this->getConfig('bucket');
        $key = $url;

        if (strpos($url, 'amazonaws.com') !== false) {

            // s3<region>.amazonaws.com/<bucket>
            if (preg_match('/^https?:\/\/s3(.+?)?\.amazonaws\.com\/(.+?)\/(.+?)$/i', $url, $matches)) {
                $region = $matches[1] ?: $region;
                $bucket = $matches[2];
                $key = $matches[3];

            // <bucket>.s3<region>.amazonaws.com
            } else if (preg_match('/^https?:\/\/(.+?)\.s3(.+?)?\.amazonaws\.com\/(.+?)$/i', $url, $matches)) {
                $bucket = $matches[1];
                $region = $matches[2] ?: $region;
                $key = $matches[3];
            }
        }

        return array(
            'bucket' => $bucket,
            'key' => trim($key, '/'),
            'region' => trim($region, '-')
        );
    }