Migrating uploads (images, videos, files) from a Linux server to AWS S3

Hello there!

I wrote a SQL sentence to update the media URL inside the database (MySQL in my case).

  1. Move the images to a new bucket
  2. Configure Strapi to upload on the new bucket
  3. Use SQL queries to modify the url and formats columns in the upload_file table

Update url column.

UPDATE files
SET url = CONCAT('<YourBucketURL>', url);

Update formats column with image sizes.

UPDATE files 
SET formats = JSON_SET(formats, '$.large.url', CONCAT('<YourBucketURL>', JSON_UNQUOTE(JSON_EXTRACT(formats, '$.large.url')))),
formats = JSON_SET(formats, '$.small.url', CONCAT('<YourBucketURL>', JSON_UNQUOTE(JSON_EXTRACT(formats, '$.small.url')))),
formats = JSON_SET(formats, '$.medium.url', CONCAT('<YourBucketURL>', JSON_UNQUOTE(JSON_EXTRACT(formats, '$.medium.url')))),
formats = JSON_SET(formats, '$.thumbnail.url', CONCAT('<YourBucketURL>', JSON_UNQUOTE(JSON_EXTRACT(formats, '$.thumbnail.url'))))
WHERE formats IS NOT NULL;

Hope it helps! :grinning:

2 Likes