doushi3819244 2014-05-08 13:55
浏览 148
已采纳

S3上传后如何返回Cloudfront网址?

I'm uploading a file to an S3 bucket for which I've created a Cloudfront distribution. I'm using the Aws\S3\S3Client class.

After uploading with putObject, the response object and the getObjectUrl method both return the object's url as https://s3-eu-west-1.amazonaws.com/mybucket/path/myfile.jpg. I am trying to get the Cloudfront url which would be something like https://d111111111ck.cloudfront.net/path/myfile.jpg.

Is there any way to get this url directly, or do I have to build it from my distribution hostname and file path?

  • 写回答

2条回答 默认 最新

  • doujiang2812 2014-05-08 14:05
    关注

    You won't get a cloudfront URL from S3, it's a different service. If your using putObject then you already know the file path (value specified in Key).

    Just return the cloudfront URL in front of the file path e.g...

    $filePath = '/path/file.jpg';
    
    $client->putObject(array(
        'Bucket' => 'mybucket',
        'Key' => $filePath,
        'SourceFile' => $fileSource,
        'ACL' => 'public-read'
    ));
    
    return 'https://d111111111ck.cloudfront.net' . $filePath;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解