【发布时间】:2017-12-08 03:09:13
【问题描述】:
这是我的代码,适用于表单上传(通过 $_FILES)(我省略了那部分代码,因为它无关紧要):
$file = "http://i.imgur.com/QLQjDpT.jpg";
$s3 = S3Client::factory(array(
'region' => $region,
'version' => $version
));
try {
$content_type = "image/" . $ext;
$to_send = array();
$to_send["SourceFile"] = $file;
$to_send["Bucket"] = $bucket;
$to_send["Key"] = $file_path;
$to_send["ACL"] = 'public-read';
$to_send["ContentType"] = $content_type;
// Upload a file.
$result = $s3->putObject($to_send);
正如我所说,如果文件是 $_FILES["files"]["tmp_name"],则此方法有效,但如果 $file 是带有未捕获异常“Aws\Exception\CouldNotCreateChecksumException”且消息为 'A sha256 checksum could not be calculated for the provided upload body, because it was not seekable. To prevent this error you can either 1) include the ContentMD5 or ContentSHA256 parameters with your request, 2) use a seekable stream for the body, or 3) wrap the non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You should be careful though and remember that the CachingStream utilizes PHP temp streams. This means that the stream will be temporarily stored on the local disk.' 的有效图像 url,则会失败。有谁知道为什么会这样?可能有什么问题? Tyvm 为您提供帮助!
【问题讨论】:
标签: php amazon-web-services amazon-s3