Skip to content

MediaField silently removes media references on save during transient storage failures #18859

@buzznick

Description

@buzznick

Describe the bug

The MediaField editor's AJAX error handler treats all HTTP errors identically — setting mediaPath: 'not-found' for 404s, 500s, and timeouts alike. On save, items marked not-found are silently stripped from MediaField.Paths, permanently deleting media references.

The server-side (Azure Blob's BlobFileStore) correctly returns 404 for missing files and 500 for transient failures, but the JavaScript error callback ignores the status code and marks the item as missing regardless.

This means any transient storage outage (Azure timeout, throttling, DNS hiccup) data loss for every content item with a MediaField that is opened and saved during the outage.

Root cause: The AJAX error callback in mediafield.js:79-88 and attachedMediaField.js:70-79 unconditionally sets mediaPath: 'not-found' without checking xhr.status. The paths computed getter then filters these out of the serialized form data before save.

Secondary bug: AwsFileStorage.cs:30-47 blanket-catches AmazonS3Exception, returning null for both 404s and transient errors, so the server always returns 404 regardless — making the JS fix insufficient for S3 users without also fixing the provider.

Orchard Core version

2.2.1/main

To Reproduce

  1. Create a content item with a MediaField referencing an existing image.
  2. Cause the storage provider to return a transient error (e.g., Azure Blob timeout producing HTTP 500).
  3. Open the content item editor in the admin panel.
  4. Observe the media item displays "Not Found — It will be discarded on saving" even though the file still exists.
  5. Click Save.
  6. The media reference is permanently removed from MediaField.Paths. When storage recovers, the file still exists but the content item no longer references it.

Expected behavior

HTTP 404 (file confirmed missing): Mark as not-found and discard on save (current behavior, correct).
HTTP 500 / timeout / other non-404 errors: Preserve the media reference and show a warning that storage may be temporarily unavailable. Do not discard the reference on save.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions