Skip to content

Shared media files

Media files uploaded to a WordPress production environment are automatically shared with and available to associated non-production environments. This eliminates the need to copy media between environments as long as the development workflow follows code moving up, and content moving down.

Once uploaded to a production environment, a media file can load at a URL with the domain of any of an application’s environments, as long as it has the same file path beginning with /wp-content/uploads/.

As an example, if a file is uploaded to an application’s production environment and available at this URL:
https://example.go-vip.net/wp-content/uploads/2022/12/image.jpg

The application’s non-production environment will also have access to that image at this URL:
https://example-preprod.go-vip.net/wp-content/uploads/2022/12/image.jpg

Additional default behavior:

  • Shared media files follow the same caching rules on all application environments.
  • Shared media files are read-only when accessed from non-production environments, protecting them from being altered unintentionally.
  • It is possible for a non-production environment to upload a file that has the same name and path as a file shared by production. In that case, the site will only override the file on the non-production environment, and the original file uploaded to production remains intact.
  • On a non-production environment it is possible to upload or import a file that has the same name and path as a file shared by production. In that case, the site will only override the file on the non-production environment, and the original file uploaded to production remains intact. If the file on the non-production environment is deleted (and the page cache for that file URL is cleared), the URL for the file will fall back to the file with the same name on production.

Limitations

  • Files can only be shared from a production environment to its associated non-production environments. Files uploaded to a non-production environment cannot be shared with the production environment.
  • The non-production environment cannot delete a file originally uploaded to the production site. The operation will not error, but the production file will not be affected and will remain available.
  • If a file uploaded to production is deleted, it will no longer be available to non-production environments.

Shared media files and the WordPress Media Library

Media files that are uploaded to a site’s WordPress Media Library have attachment data that is stored in the site’s database. Media files will not appear in a site’s WordPress media library unless that attachment data exists in the database.

Though media files are automatically shared from a production environment to a non-production environment, a data sync from a production environment to a non-production environment must occur in order for the WordPress Media Library of the non-production environment to load the media files as expected.

Last updated: August 08, 2024

Relevant to

  • WordPress