This is driving me mad. I am uploading images to S3 using the php SDK. Whenever I browse to the image URL, the browser downloads the image opposed to displaying it.
这让我很生气。我正在使用php SDK将图像上传到S3。每当我浏览图像URL时,浏览器都会下载与显示图像相反的图像。
I think its something to do with content type.
我认为它与内容类型有关。
// Prepare to upload the file to S3 bucket.
$s3->create_object($bucket, $file_name, array(
'contentType' => 'binary/octet-stream',
'acl' => AmazonS3::ACL_PUBLIC
));
Can you help?
你能帮我吗?
thanks
谢谢
4 个解决方案
#1
16
$s3->create_object($bucket, $file_name, array(
'fileUpload' => $resized_image,
'contentType' => $_FILES['image']['type'],
'acl' => AmazonS3::ACL_PUBLIC
));
#2
13
Your content type is wrong indeed. It needs to be image/jpeg for JPGs, for instance. See this site for a list: http://en.wikipedia.org/wiki/Internet_media_type
您的内容类型确实是错误的。例如,它需要是JPG的image / jpeg。请访问此站点以获取列表:http://en.wikipedia.org/wiki/Internet_media_type
#3
2
Working on your own, seemingly valid, assumption that it is the content type:
依靠自己,看似有效,假设它是内容类型:
You need to set the correct content type for the image being upload, the following list contains all the most common types
您需要为要上载的图像设置正确的内容类型,以下列表包含所有最常见的类型
* image/gif: GIF image
* image/jpeg: JPEG JFIF image
* image/png: Portable Network Graphics
* image/svg+xml: SVG vector image
* image/tiff: Tag Image File Format
* image/vnd.microsoft.icon: ICO image
So a rework of your sample code for a png upload:
因此,为png上传重新编写示例代码:
// Prepare to upload the file to S3 bucket.
$s3->create_object($bucket, $file_name, array(
'contentType' => 'image/png',
'acl' => AmazonS3::ACL_PUBLIC
));
#4
2
If you are working URL images use
如果您正在使用URL图像
'ContentType' => mime_content_type($absolutePathToImage),
instead of
代替
$_FILES['image']['type']
#1
16
$s3->create_object($bucket, $file_name, array(
'fileUpload' => $resized_image,
'contentType' => $_FILES['image']['type'],
'acl' => AmazonS3::ACL_PUBLIC
));
#2
13
Your content type is wrong indeed. It needs to be image/jpeg for JPGs, for instance. See this site for a list: http://en.wikipedia.org/wiki/Internet_media_type
您的内容类型确实是错误的。例如,它需要是JPG的image / jpeg。请访问此站点以获取列表:http://en.wikipedia.org/wiki/Internet_media_type
#3
2
Working on your own, seemingly valid, assumption that it is the content type:
依靠自己,看似有效,假设它是内容类型:
You need to set the correct content type for the image being upload, the following list contains all the most common types
您需要为要上载的图像设置正确的内容类型,以下列表包含所有最常见的类型
* image/gif: GIF image
* image/jpeg: JPEG JFIF image
* image/png: Portable Network Graphics
* image/svg+xml: SVG vector image
* image/tiff: Tag Image File Format
* image/vnd.microsoft.icon: ICO image
So a rework of your sample code for a png upload:
因此,为png上传重新编写示例代码:
// Prepare to upload the file to S3 bucket.
$s3->create_object($bucket, $file_name, array(
'contentType' => 'image/png',
'acl' => AmazonS3::ACL_PUBLIC
));
#4
2
If you are working URL images use
如果您正在使用URL图像
'ContentType' => mime_content_type($absolutePathToImage),
instead of
代替
$_FILES['image']['type']