/** * Upload an object. * * @param $path * @param $body * @param Config $config * * @return array */ protected function upload($path, $body, Config $config) { $key = $this->applyPathPrefix($path); $mimetype = MimeType::detectByFileExtension(pathinfo($path, PATHINFO_EXTENSION)); $config->set('mimetype', $mimetype); $return = parent::upload($path, $body, $config); if (function_exists('getimagesizefromstring') && strpos($mimetype, 'image') !== false) { if (is_resource($body)) { rewind($body); $size = getimagesizefromstring(stream_get_contents($body)); } else { $size = getimagesizefromstring($body); } $this->s3Client->copyObject(['Bucket' => $this->bucket, 'CopySource' => $this->bucket . DS . $key, 'ContentType' => $mimetype, 'Metadata' => ['width' => $size[0], 'height' => $size[1]], 'MetadataDirective' => 'REPLACE', 'Key' => $key]); } return $return; }