dtkmejg127475 2015-04-04 11:14
浏览 71
已采纳

在aws S3上检查文件是图像还是xml

I need a away to see if an image exist on the S3 cloud, I'm build an APP to sort of merge data from local to the web, it is actually simple and I almost done, from the local app I'm getting a json post... so on that json I'm getting an image name "prety_image.jpg" which then is save to the DB, but before i save it I need to check if that image exist in the S3 cloud, I have the S3 url ... //foo.cloudfront.net/ and to display the image all I do is add the name of the image... for what I have seen is that if the image do exist it display the image.. but if the image doesn't exist I'm getting an xml file

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>13A57760</RequestId>
<HostId>3/uj7Ro77bGnjzGZVABUXvVVg4=</HostId>
</Error>

so what I want is that if i'm getting this error then save a blank image if not then just save the image... but I don;t know how to do it... I haven't use aws sdk, i downloaded but I don't know what to do with it... I have use other SDK's but AWS SDK is just way to much for my brain..

  • 写回答

1条回答 默认 最新

  • dryeyhe0266 2015-04-04 11:54
    关注

    I find a solution without the use of AWS SDK, is actually very simple...
    This function is inside my class but I'm just gonna put it here...

    function httperr($url)
        {
            $headers = get_headers($url);
            return substr($headers[0], 9, 3);
        }
    

    The I just call it like this

    if (intval(httperr(S3AWS . $img)) === 200) {
        $image = '<img src="'.S3AWS . $img.'" > <br>- Exist';
    } else {
        $image = 'No image here...';
    }
    

    the S3AWS is the url and the $img is just the name of the image... so if the header is ok 200 then the image do exist if not then there is no image, and is working just fine...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?