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...

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

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码