【问题标题】:How to get the file from Amazon AWS S3 bucket from URL?如何从 URL 获取来自 Amazon AWS S3 存储桶的文件?
【发布时间】:2016-11-11 19:54:24
【问题描述】:

我创建了一个 Amazon S3 存储桶,并从手机应用程序上传了文件/图像。我必须展示带有大量图像的帖子,并且图像会自动绑定到图像 URL。但我不知道如何获取 URL,因为图像不应该公开直接显示。如何在我的应用中显示它们?

$cmd = $client->getCommand('GetObject',[
    'Bucket' => 'myinstaclassbucket',
'Key' => 'e12e682c-936d-4a97-a049-6f104dd7c904.jpg',
    ]);
$request = $client->createPresignedRequest($cmd,$timetoexpire);
$presignedurl = (string) $request->getUri();
echo $presignedurl;

【问题讨论】:

  • 您需要 S3Client 从这里 aws.amazon.com/documentation 使用密钥和访问密钥生成 URL。我可以提供示例,但它会在 PHP 中。
  • 谢谢,如果你能给我一个 PHP 的例子,那就太好了,因为该服务是用 PHP 开发的。谢谢贾斯汀纳斯 :)

标签: amazon-web-services amazon-s3 xamarin.forms


【解决方案1】:

首先你需要使用AWS PHP SDK。还要确保您拥有有效的访问密钥和密钥。

比一切都直截了当。

$bucket = 'some-bucket';
$key = 'mainFolder/subFolder/file.xx';

// Init client
$client = new S3Client([
    'key' => '*YOUR ACCESS KEY*',
    'secret' => '*YOUR SECRET KEY*',
]);

if ($client->doesObjectExists($bucket, $key)) {
    // If passing `expire` time you will get signed URL
    $url = $client->getObjectUrl($bucket, $key, time() + (60 * 60 * 2));
} else {
    $url = null;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2016-02-01
    • 2015-11-22
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多