快轉到主要內容

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

428 字1 分鐘00
作者Y Cheung

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

Drupal log messeages
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 S3FS config
S3 File System settings > action > Refresh file metadata cache️
分享

相關文章

Drupal 9 Twig 獲取field值速查表

作者 Y Cheung999 字2 分鐘00

在Drupal 8 和 Drupal 9 的 twig 模板開發中,常常會需要輸出指定的field,本文列出常見類型的field取值方法,以便查詢。 一般類型 General …

↑