解決 Drupal 9 Media 列表縮略圖無法生成問題

解決 Drupal 9 Media 列表縮略圖無法生成問題
Fix Source Image not Found While Trying to Generate Derivative Image for Drupal 9

站點安裝設置失誤導致在S3上缺失了 public://media-icons/ 下的所有文件,如今在media 中上傳任何 video、document、audio 都無法生成縮略圖,fallback 到本地path 提示 404 not found,檢視 Recent log messages 日誌,發現了相關錯誤信息:

Drupal 9 Source image not found while trying to generate derivative image.
Source image at public://media-icons/generic/video.png not found while trying to generate derivative image at public://styles/thumbnail/public/media-icons/generic/video.png.
當前使用的是 Drupal v9.3.3 和 s3fs 模組 v3.0.0-beta4 版本。

Y Cheung 嘗試手動在AWS S3中創建文件夾 media-icons/generic 並上傳圖片,問題仍未解決。

但是用drush打印  \\Drupal::service('file_url_generator')->generateAbsoluteString("public://media-icons/generic/video.png") 的結果,確認已經是正確的URL了,該地址也可以被公開訪問,奇怪。

後來Y Cheung找到了這篇 「"Image styles: Error generating image, missing source file" still an issue 」:

For the s3fs module the s3fs_file SQL table is considered authoritative of the files list in the bucket. If a file is not listed in this database table it is not considered to be in the bucket and file_exists() should return false.

原來 S3fs 模組判斷一個文件是否存在是查詢數據庫表的(表名 s3fs_file),而不是查詢 AWS S3服務。所以,如文內所述,只要去 S3fs 模組設置中(/admin/config/media/s3fs/actions)的 FILE METADATA CACHE 刷新一下就好了。

Drupal 9 S3 File System settings
S3 File System settings > action > Refresh file metadata cache️
Y Cheung

Y Cheung

Blogger, Programer & Traveler.
Shanghai