我正在将文件上传到 S3,没有出现如下错误:
$s3 = new Aws\S3\S3Client([
"version" => "latest",
"region" => $region
]);
$result = $s3->putObject([
"Bucket" => $bucket,
"Key" => $key,
"SourceFile" => $image,
"ACL" => "public-read"
]);
我读过有关 Etags 和 ContentMD5 header 的内容,但我似乎无法将它们全部放在 PHP 中。
如何知道文件内容是否正确?
最佳答案
使用 ContentSHA256 key 使其正常工作:
$sha256 = hash_file("sha256", $image);
$result = $s3->putObject([
"Bucket" => getenv("S3_BUCKET_NAME"),
"Key" => $key,
"SourceFile" => $image,
"ACL" => "public-read",
"ContentSHA256" => $sha256
]);
如果 SHA 不匹配,我会收到 S3 异常,这正是我想要的。
关于php - 在 PHP 中使用 md5 验证 S3 上传是否成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37588739/