#82855Update preview image of online media files on save
Description
If you add an online media file (YouTube or Vimeo) via file list module in TYPO3 backend a preview image is saved to typo3temp/online_media. This file will be used as a preview image until the end of time unless it is deleted. In my use case an editor adds an online media file and later changes the preview image on the YouTube website. This new preview image will never be used in TYPO3 because there is a check for an existing preview image (file_exists) in method getPreviewImage(File $file) in class TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\YouTubeHelper (it’s the same for Vimeo):
public function getPreviewImage(File $file)
{
$videoId = $this->getOnlineMediaId($file);
$temporaryFileName = $this->getTempFolderPath() . 'youtube_' . md5($videoId) . '.jpg';
if (!file_exists($temporaryFileName)) {
$tryNames = ['maxresdefault.jpg', '0.jpg'];
foreach ($tryNames as $tryName) {
$previewImage = GeneralUtility::getUrl(
sprintf('https://img.youtube.com/vi/%s/%s', $videoId, $tryName)
);
if ($previewImage !== false) {
file_put_contents($temporaryFileName, $previewImage);
GeneralUtility::fixPermissions($temporaryFileName);
break;
}
}
}
return $temporaryFileName;
}
This method is called everytime a backend user opens the file list view. I suggest to call a slightly modified version of this method on online media file save without the check for an existing preview image. This way an editor would be able to update preview images without asking a administrator to delete the preview file from typo3temp/online_media.
Reviews 6
- 13.4 89072[BUGFIX] Avoid using native filemtime for calculation of paths
- main 89052[BUGFIX] Avoid using native filemtime for calculation of paths
- 12.4 87535[BUGFIX] Prevent rendering of empty image thumbnail in FileList
- main 81099[BUGFIX] Use proper FAL API for cache busting
- main 81083[FEATURE] Allow updating online media assets
- main 54555[BUGFIX] Update online media preview image when original preview changes