strapi-community / strapi-provider-upload-google-cloud-storage

Google Cloud Storage Upload Provider for Strapi
MIT License
211 stars 94 forks source link

Changing the baseUrl property doesn't affect existing uploads #172

Closed ciriousjoker closed 1 year ago

ciriousjoker commented 1 year ago

Describe the bug I just set a baseUrl for production. There exist many previously uploaded files (at that point, baseUrl was undefined).

To Reproduce Steps to reproduce the behavior:

  1. Create strapi instance
  2. Upload image
  3. Set baseUrl to some other value
  4. Upload image

Expected behavior Api returns both images as being hosted from the new baseUrl.

Actual behavior Api returns a different baseUrl for each image

Desktop (please complete the following information): N/A

Smartphone (please complete the following information): N/A

Additional context I've considered updating the sql table manually, but I'm not too familiar with sql and modifying a json string via sql sounds like a terrible idea.

ciriousjoker commented 1 year ago

So apparently these seems to work:

UPDATE files
SET formats = replace(formats::TEXT, 'https://storage.googleapis.com/CHANGETHIS/', 'https://example.com/')::jsonb;
UPDATE files
SET url = replace(url::TEXT, 'https://storage.googleapis.com/CHANGETHIS/', 'https://example.com/')::varchar(255);

Adapted from source: https://stackoverflow.com/a/71221922/5854364

Use at your own risk.

Since there exists a reasonable workaround, I'm closing this.