amazon s3 - 图像下载而不是显示在浏览器中

2022-08-30 13:57:57

这让我发疯。我正在使用 php 开发工具包将图像上传到 S3。每当我浏览到图像URL时,浏览器都会下载图像而不是显示它。

我认为这与内容类型有关。

        // Prepare to upload the file to S3 bucket.
        $s3->create_object($bucket, $file_name, array(
                'contentType' => 'binary/octet-stream',
                'acl' => AmazonS3::ACL_PUBLIC
        ));

你能帮忙吗?

谢谢


答案 1
            $s3->create_object($bucket, $file_name, array(
                    'fileUpload' => $resized_image,
                    'contentType' => $_FILES['image']['type'],
                    'acl' => AmazonS3::ACL_PUBLIC
            ));

答案 2

您的内容类型确实是错误的。例如,对于JPG,它需要是图像/ jpeg。有关列表,请参阅此站点:http://en.wikipedia.org/wiki/Internet_media_type


推荐