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

查看:576
本文介绍了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天全站免登陆