Asked  7 Months ago    Answers:  5   Viewed   31 times

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

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

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

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

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.

I have tried:

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

but that returns the content of the file.

$contents = $filemanager->listContents();

or

$paths = $filemanager->listPaths();

but they give me the relative paths to my files.

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

 Answers

90

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.

Wednesday, March 31, 2021
 
RenegadeAndy
answered 7 Months ago
100

Just add them to the string.

return redirect()->away('http://bla.com?bla=bla');

The second parameter for this function is the http status that should be sent to the visitor. So when you add an array this is parsed as a 1.

Saturday, May 29, 2021
 
Claudio
answered 5 Months ago
40

Similar issue happens in my local homestead development while my app running on Linode works fine.

After checking S3 permission, checked out old version, etc., this problem disappear when I restart homestead.

homestead halt
homestead up --provision
Saturday, May 29, 2021
 
Zigglzworth
answered 5 Months ago
87

Try to use the following:

Request::getRequestUri()
Sunday, August 8, 2021
 
ProfK
answered 3 Months ago
26

Set url to your cloudfront url in config/filesystems/s3

's3' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => 'http://xxx.cloudfront.net']

It works in L5.5

Saturday, August 14, 2021
 
Wilk
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :