Laravel League/flysystem 使用 AWS S3 获取文件 URL [英] Laravel league/flysystem getting file URL with AWS S3

查看:41
本文介绍了Laravel League/flysystem 使用 AWS S3 获取文件 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于 League/flysystem 在 Laravel 中构建文件管理系统:https://github.com/thephpleague/flysystem

I am trying to build a file management system in Laravel based on league/flysystem: https://github.com/thephpleague/flysystem

我正在使用 S3 适配器,我使用它来保存上传的文件:

I am using the S3 adapter and I have it working to save the uploaded files using:

$filesystem->write('filename.txt', 'contents');

现在我在使用 S3 适配器时被困在生成下载文件 URL.

Now I am stuck on generating the download file URL when using the S3 adapter.

文件正确保存在S3存储桶中,我有访问权限,只是不知道如何通过league/flysystem包访问S3 getObjectUrl方法.

The files are saved correctly in the S3 bucket, I have permissions to access them, I just don't know how to get to the S3 getObjectUrl method through the league/flysystem package.

我试过了:

$contents = $filesystem->read('filename.txt');

但这会返回文件的内容.

but that returns the content of the file.

$contents = $filemanager->listContents();

$paths = $filemanager->listPaths();

但他们给了我文件的相对路径.

but they give me the relative paths to my files.

我需要的是类似于ht...//[s3-region].amazonaws.com/[bucket]/[dir]/[file]..."

What I need is something like "ht...//[s3-region].amazonaws.com/[bucket]/[dir]/[file]..."

推荐答案

我不确定使用 Flysystem 执行此操作的正确方式是什么,但是底层的 S3Client 对象有一个方法可以做到这一点.你可以做 $filesystem->getAdapter()->getClient()->getObjectUrl($bucket, $key);.当然,构建 URL 与您描述的一样微不足道,因此您实际上不需要特殊的方法来完成.

I'm not sure what the correct way of doing this is with Flysystem, but the underlying S3Client object has a method for doing that. You could do $filesystem->getAdapter()->getClient()->getObjectUrl($bucket, $key);. Of course, building the URL is as trivial as you described, so you don't really need a special method to do it.

这篇关于Laravel League/flysystem 使用 AWS S3 获取文件 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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