Report this

What is the reason for this report?

SignatureDoesNotMatch error with special characters in the file name

Posted on November 6, 2019

When adding a special character to a file name, the file upload results into an error. I’m using the Spaces-API PHP library with the latest AWS S3 client, as recommended in the DigitalOcean documentation.

Example: image.png uploads fine image@2x.png results in error

The error:

Exception has occurred.
GuzzleHttp\Exception\ClientException: Client error: `PUT https://foo.ams3.digitaloceanspaces.com/staging/test/s/Test2%40x5dc343e17c8838.99908039.png` resulted in a `403 Forbidden` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx00000000000 (truncated...)

Example code to reproduce the error:

// Connect
$space = new SpacesConnect($key, $secret, $space_name, $region);

// Generate file id
$file_id = uniqid('', true);

// File name
$filename  = $file_id . '@2x.png';

// Path to file
$path_file = 'test/' . $filename;

// Upload source file to CDN
$space->UploadFile($data, 'public', $path_file, '', $mime);

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.