Attaching uploaded media file to content fails on node edit form

Created on 26 June 2025, 10 days ago

Problem

We are using a Drupal 10.4.x site with the Media module enabled. Randomly, we encounter an issue where attaching a new media item fails in the Media Library popup dialog on the node edit form. Instead of updating the form with the selected media, the request fails, and the expected behavior (e.g., displaying the media item in the "Main Image" field) does not occur. This issue appears intermittently and, once triggered, tends to repeat multiple times in a row before resolving spontaneously for days.

Steps to reproduce

  1. Navigate to the node add/edit form (e.g., "Create Landing page") and locate a media field (e.g., "Main Image").
  2. Click the "Add media" button to open the Media Library popup dialog.
  3. Attempt to add or select a new media item (e.g., by clicking "Choose File" or selecting an existing item).
  4. Observe if the XHR request is initiated by jquery.min.js or "Other", the latter meaning the attachment will fail. The accept headers are also wrong at the same time both in the request and the response.
  5. Note that the media item is not attached to the form, but the response is displayed on the browser window as is.
  6. The issue is hard to reproduce consistently due to its occasional nature. When it occurs, it may persist across multiple attempts but can resolve after an unspecified period (days).

Additional Observations

  • Cache Correlation: We’ve identified that running drush cr (cache rebuild) resolves the issue temporarily, allowing media uploads to work as expected until the problem reoccurs. After clearing the cache, the Media Library dialog functions normally (e.g., selecting "Choose File" successfully uploads the media, and the form updates as it normally does).

Has anyone else experienced similar intermittent Media Library AJAX failures resolved by cache rebuilds? Any insights that could cause this behavior would be greatly appreciated. We are open to testing patches or providing additional debugging information.

💬 Support request
Status

Active

Version

10.4 ✨

Component

media system

Created by

🇫🇮Finland tomimikola

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

Comments & Activities

Production build 0.71.5 2024