Error: Object of class Drupal\ai\OperationType\GenericType\VideoFile could not be converted to string in file_put_contents() (line 498 of /var/www/html/testu/web/core/lib/Drupal/Core/File/FileSystem.php)
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3551584. --> Reported by: [fishfree](https://www.drupal.org/user/175299) >>> <p>For ImageToVideo OperationType, the following lines will throw exception:</p> <pre>&nbsp; ...&nbsp; <br>&nbsp; $mp4_binary_string = file_get_contents($video_url);<br>&nbsp; $video_file = new VideoFile($mp4_binary_string, 'video/mp4', 'alibabacloud' . md5($video_url) . '.mp4');<br>return new ImageToVideoOutput([$video_file], $response, ['source_url' =&gt; $video_url]);</pre><p>The calling stack is as below:</p> <pre>Error: Object of class Drupal\ai\OperationType\GenericType\VideoFile could not be converted to string in file_put_contents() (line 498 of /var/www/html/testu/web/core/lib/Drupal/Core/File/FileSystem.php)<br>#0 /var/www/html/testu/web/core/lib/Drupal/Core/File/FileSystem.php(498): file_put_contents()<br>#1 /var/www/html/testu/web/modules/contrib/ai/modules/ai_api_explorer/src/Plugin/AiApiExplorer/ImageToVideoGenerator.php(154): Drupal\Core\File\FileSystem-&gt;saveData()<br>#2 /var/www/html/testu/web/modules/contrib/ai/modules/ai_api_explorer/src/Form/AiApiExplorerForm.php(82): Drupal\ai_api_explorer\Plugin\AiApiExplorer\ImageToVideoGenerator-&gt;getResponse()<br>#3 [internal function]: Drupal\ai_api_explorer\Form\AiApiExplorerForm-&gt;ajaxResponse()<br>#4 /var/www/html/testu/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php(69): call_user_func_array()<br>#5 /var/www/html/testu/web/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php(112): Drupal\Core\Form\FormAjaxResponseBuilder-&gt;buildResponse()<br>#6 /var/www/html/testu/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber-&gt;onException()<br>#7 /var/www/html/testu/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}()<br>#8 /var/www/html/testu/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher-&gt;callListeners()<br>#9 /var/www/html/testu/vendor/symfony/http-kernel/HttpKernel.php(241): Symfony\Component\EventDispatcher\EventDispatcher-&gt;dispatch()<br>#10 /var/www/html/testu/vendor/symfony/http-kernel/HttpKernel.php(91): Symfony\Component\HttpKernel\HttpKernel-&gt;handleThrowable()<br>#11 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel-&gt;handle()<br>#12 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session-&gt;handle()<br>#13 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle()<br>#14 /var/www/html/testu/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength-&gt;handle()<br>#15 /var/www/html/testu/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength-&gt;handle()<br>#16 /var/www/html/testu/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache-&gt;pass()<br>#17 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache-&gt;handle()<br>#18 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle()<br>#19 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(53): Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle()<br>#20 /var/www/html/testu/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle()<br>#21 /var/www/html/testu/web/core/lib/Drupal/Core/DrupalKernel.php(715): Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle()<br>#22 /var/www/html/testu/web/index.php(19): Drupal\Core\DrupalKernel-&gt;handle()<br>#23 {main}<br>.</pre><p>Acturally, I can download the $video_url with Chrome or Edge and play the MP4 video normally.</p> > Related issue: [Issue #3567244](https://www.drupal.org/node/3567244)
issue