I have a code that works well with S3, but after switching to Spaces it doesn’t check the MD5 hash. So even if I change the $md5
variable, the upload finishes successfully.
The fun fact is that this is only a problem with content-md5
. The content-type
check works fine.
Is there a way to check the file integrity after uploading in Spaces?
I have no idea how to fix it.
$formInputs = [
'acl' => 'private',
'key' => $name,
'success_action_status' => '201',
'content-md5' => $md5,
'content-type' => $contentType,
];
$options = [
['acl' => 'private'],
['bucket' => $bucket],
['success_action_status' => '201'],
['content-md5' => $md5],
['content-type' => $contentType],
['content-length-range', 0, 1024 * 1024 * 100],
['starts-with', '$key', $userId . '/'],
];
$postObject = new PostObjectV4($client, $bucket, $formInputs, $options, '+15 minutes');
$formAttributes = $postObject->getFormAttributes();
$formInputs = $postObject->getFormInputs();
return [$formAttributes, $formInputs];
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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hello,
To ensure the
content-md5
check is enforced when using the PostObjectV4 with PHP for uploads to DigitalOcean Spaces, you would usually include the MD5 hash in the headers of your request, which you seem to be doing. However, it seems like Spaces may not be validating thecontent-md5
header the same way that Amazon S3 does, or it might not be supported in the same manner.While DigitalOcean Spaces is designed to be compatible with the S3 API, there could be subtle differences in the way certain features are implemented or supported. If you’re still facing issues with the
content-md5
check not being enforced, one potential workaround is to perform the MD5 check manually after the file has been uploaded. You can download the file after upload and check the MD5 of the downloaded file against the expected hash. If they do not match, you could then handle the discrepancy accordingly in your application logic.Another option could be to reach out to DigitalOcean support to confirm the behavior you’re observing with the
content-md5
header, as there may be nuances with their implementation or recent changes that aren’t reflected in the documentation.If they confirm that this is indeed not supported, the best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.
Hope that helps!
- Bobby.