I am converting a client from AWS S3 to Spaces for her large files. There are several hundred files totaling about 500 GBs. All of the folders and file names on AWS S3 contain space characters. The default replacement on AWS for a space character in a URL is a plus sign (+), so all of her URL references in her WordPress site have plus signs in place of the space characters (e.g., https://s3.amazonaws.com/bucket/Addiction+2017/Addiction+2017.pdf). I rcloned all of the files from AWS S3 to our Spaces repository, but the default replacement character for a space on Spaces is %20, so the above URL on Spaces is https://subdomain.domain.com/Addiction 2017/Addiction +2017.pdf. I’ve been trying to use Interconnect/IT’s Search and Replace tool to do the replacements in the database, but I can’t get it to work. My next approach was to see if I could reclone the the files and tell Spaces to use a plus sign (+) instead of %20 for the web safe replacement. Can I do that? Any other ideas? I can’t change the files on AWS because they are in active use on the current website. Any help and advice is greatly appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
Unfortunately, there’s no current way in Spaces to change the encoding from %20 back to +. This behavior is hard-coded into the system. It’s generally recommended as per URL encoding rules to use %20 for space characters in URLs.
Beyond manually changing the URLs stored in your database (which can be risky), you might consider using a script to pull down, rename, and re-upload your files. Ensure you have proper backups and you’ve tested this on non-production data before you proceed with any mass-renaming operations.
A possible solution can be to write code to fetch the file from Spaces and serve it through a PHP script (adjust according to your application language) where it’s URL decoded before it’s sent. Here’s a rough example of how to do it:
- <?php
- $file = 'path/to/spaces/file.pdf';
- $decodedFile = urldecode($file);
- header('Content-Type: application/octet-stream');
- header("Content-Transfer-Encoding: Binary");
- header("Content-disposition: attachment; filename=\"" . basename($decodedFile) . "\"");
- readfile($file);
- ?>
Please remember to replace ‘path/to/spaces/file.pdf’ with the path to your file in Spaces.
While this solution is more of a workaround, it should allow your client to use filenames with spaces without requiring modification of the WordPress data.
For more information on working with Spaces, you can refer to our DigitalOcean Spaces documentation.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.