TypeError: Argument 1 passed to guessMimeType() must be string not object

Created on 22 February 2023, almost 2 years ago
Updated 23 February 2023, almost 2 years ago

I'm trying to write some data ($response) which is in object format using the below code.

$fileRepository = \Drupal::service('file.repository');
$uri = $fileRepository->writeData($response, $directory, FileSystemInterface::EXISTS_REPLACE);

Receiving the below error:

TypeError: Argument 1 passed to Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser::guessMimeType()
must be of the type string, object given, called in /drupal/core/modules/file/src/Entity/File.php on line
165 in Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser->guessMimeType() (line 73 of /drupal/core/lib/Drupal/Core/ProxyClass/File/MimeType/MimeTypeGuesser.php)

I've tried the below,
1. Using print_r($response, true) and it's throws array given
2. Using serialize($response) and it's retruns GuzzleHttp content since $response is holding API returned values.

Environment versions are, Drupal:9.5.1, PHP:7.3.28, MariaDB:10.5.10 & nginx:1.20.0

💬 Support request
Status

Closed: outdated

Version

9.5

Component
File system 

Last updated 1 day ago

Created by

🇮🇳India magendiran

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024