amazon s3 - image downloading instead of displaying in browser amazon s3 - image downloading instead of displaying in browser php php

amazon s3 - image downloading instead of displaying in browser


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


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


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:

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