Ejemplo n.º 1
0
 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;
         }
     }
 }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 /**
  * 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';
     }
 }
Ejemplo n.º 4
0
 /**
  * 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);
 }
Ejemplo n.º 5
0
 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);
     });
 }
Ejemplo n.º 6
0
 public function testReturnsNullWhenNoMatchFound()
 {
     $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar'));
 }