How to Save Relative Image Paths in Strapi Media Library and Dynamically Build Absolute Paths

How to Save Relative Image Paths in Strapi Media Library and Dynamically Build Absolute Paths

System Information
  • Strapi Version: 4.3.9
  • Operating System: Windows
  • Database: postgreSQL
  • Node Version: 18.20.4
  • NPM Version: 10.7.0
  • Yarn Version: 1.22.22

Hi everyone,

I’m working on a project using Strapi with MinIO as the file storage provider, and I’ve encountered an issue with how Strapi saves media file paths in the database.

Currently, Strapi stores the absolute file URL (e.g., https://minio....[ID_image].[format]) in the files table of the database for media items (images, videos, etc.). However, I would like to store only the relative path (e.g., [ID_image].[format]) and dynamically construct the absolute path on the backend, with the base URL being read from an environment variable.

Could anyone advise what configurations or code changes are necessary to achieve this? I would appreciate any pointers on how to modify Strapi’s behavior to save relative paths and build the full URL at the backend level using an environment variable for the base path.

Thanks in advance for your help!

1 Like

I have the same issue like you.

1 Like