protected function prepareParams() { // Set the content type, if not specified, and can be detected. if (!isset($this->config['initiate']['params']['ContentType']) && ($uri = $this->source->getMetadata('uri'))) { if ($mimeType = Mimetypes::getInstance()->fromFilename($uri)) { $this->config['initiate']['params']['ContentType'] = $mimeType; } } }
private function addContentType(RequestInterface $request, StreamInterface $body) { if (!($uri = $body->getMetadata('uri'))) { return; } // Guess the content-type based on the stream's "uri" metadata value. // The file extension is used to determine the appropriate mime-type. if ($contentType = Mimetypes::getInstance()->fromFilename($uri)) { $request->setHeader('Content-Type', $contentType); } }
/** * Applies default Content-Disposition and Content-Type headers if needed. */ private function prepareDefaultHeaders() { // Set a default content-disposition header if one was no provided if (!$this->hasHeader('Content-Disposition')) { $this->headers['Content-Disposition'] = sprintf('form-data; name="%s"; filename="%s"', $this->name, basename($this->filename)); } // Set a default Content-Type if one was not supplied if (!$this->hasHeader('Content-Type')) { $this->headers['Content-Type'] = Mimetypes::getInstance()->fromFilename($this->filename) ?: 'text/plain'; } }
/** * Write the given image * @param string $filename * @param Stream $image */ private function writeImage($filename, Stream $image) { $filename = $this->getDestinationPath($filename); $resource = $image->detach(); $config = ['visibility' => 'public', 'mimetype' => Mimetypes::getInstance()->fromFilename($filename)]; if ($this->fileExists($filename)) { return $this->filesystem->disk($this->getConfiguredFilesystem())->updateStream($filename, $resource, $config); } $this->filesystem->disk($this->getConfiguredFilesystem())->writeStream($filename, $resource, $config); }
public function stream_flush() { if ($this->mode == 'r') { return false; } $this->body->seek(0); $params = $this->getOptions(); $params['Body'] = $this->body; // Attempt to guess the ContentType of the upload based on the // file extension of the key if (!isset($params['ContentType']) && ($type = Mimetypes::getInstance()->fromFilename($params['Key']))) { $params['ContentType'] = $type; } return $this->boolCall(function () use($params) { return (bool) $this->getClient()->putObject($params); }); }
public function testReturnsNullWhenNoMatchFound() { $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar')); }