PHP的Amazon S3访问过的网址私人文件 [英] PHP Amazon S3 access private files through URL

查看:219
本文介绍了PHP的Amazon S3访问过的网址私人文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 AWS PHP SDK将图像保存在S3上。文件被私下保存。然后,我展示使用S3文件的URL在我的web应用程序的缩略图,但由于这些文件是私人的,因此图像显示为已损坏。

I'm using AWS PHP sdk to save images on S3. Files are saved privately. Then, I'm showing the image thumbnails using the S3 file url in my web application but since the files are private so the images are displayed as corrupt.

当用户点击文件的名称,一个模式被打开,以显示在大尺寸的文件,但文件显示为腐败有作为由于同样的问题。

When the user clicks on the name of file, a modal is opened to show the file in larger size but file is displayed as corrupt there as well due to the same issue.

现在,我知道有两种方法可以使这个工作。 1。使文件公开。 2.生成pre签署的网址文件。但是我可以与任何这两个选项,由于我的项目的要求不下去。

Now, I know that there are two ways to make this working. 1. Make the files public. 2. Generate pre-signed urls for files. But I cannot go with any of these two options due to the requirements of my project.

我的问题是有解决这个问题的任何第三条道路?

My question is that is there any third way to resolve this issue?

推荐答案

我会强烈反对这项建议,但你可以创建一个通过API拉图像,高速缓存,并提供自己的服务器上的脚本。然后,您可以限制访问,只要你喜欢不使图像公众。

I'd highly advise against this, but you could create a script on your own server that pulls the image via the API, caches it and serves. You can then restrict access however you like without making the images public.

例通过脚本:

$headers = get_headers($realpath); // Real path being where ever the file really is

foreach($headers as $header) {
    header($header);
}
$filename = $version->getFilename();

// These lines if it's a download you want to do
// header('Content-Description: File Transfer');
// header("Content-Disposition: attachment; filename={$filename}");

$file = fopen($realpath, 'r');
fpassthru($file);
fclose($file);
exit;

这也就勉强摸边,不应该耽误您的文件的外观太多,但T的还是要采取一定的资源和带宽。

This will barely "touch the sides" and shouldn't delay the appearance of your files too much, but t's still going to take some resources and bandwidth.

这篇关于PHP的Amazon S3访问过的网址私人文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆