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

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条)

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择