图像未从aws加载

时间:2014-05-22 05:33:42

标签: php amazon-web-services

我想在亚马逊s3的图片标签中显示图片

<img alt="" class="pictureWidth" src="https://xyz.s3.amazonaws.com/images/estimates/1_6.jpg">

我检查过该图片位于该位置并且有权限,我也在浏览器中运行该网址,如下所示

images/estimates/1_6.jpg

按照上传图片的示例代码

$result = $s3->putObject(array(
            'Bucket'       => $s3bucketName,
            'Key'          => $fileName,
            'Body'         => $fileName,
            'ContentType'  => 'text/plain',
            'ACL'          => 'public-read',
            'StorageClass' => 'REDUCED_REDUNDANCY',
       ));

我也试过'ContentType'=&gt; 'image / jpeg',但没有运气

https://servicefusion.s3.amazonaws.com/images/estimates/7.jpg

问题是什么?

2 个答案:

答案 0 :(得分:0)

   $result = $s3->putObject(array(
        'Bucket'       => $s3bucketName,
        'Key'          => $fileName,
        'Body'         => $fileName,
        'ContentType'  => 'image/jpeg',
        'ACL'          => 'public-read',
        'StorageClass' => 'REDUCED_REDUNDANCY',
   ));

<强>更新 刚刚更新的是image/jpeg而不是images/jpeg

其他类型的文件类型请到此处参考:
http://www.utoronto.ca/web/htmldocs/book/book-3ed/appb/mimetype.html

如果那不是您的问题,请参阅:

http://s3browser.com/features-content-mime-types-editor.php

答案 1 :(得分:0)

您不应使用'Body',而应使用'SourceFile',否则您将上传文件名为其内容的文件。

$result = $s3->putObject(array(
    'Bucket'       => $s3bucketName,
    'Key'          => $fileName,
    'SourceFile'   => $fileName,
    'ContentType'  => 'image/jpeg',
    'ACL'          => 'public-read',
    'StorageClass' => 'REDUCED_REDUNDANCY',
));

另请参阅:putObject