barryvdh / laravel-elfinder

elFinder bundle for Laravel
738 stars 171 forks source link

s3 url not displayed #236

Open og6k opened 6 years ago

og6k commented 6 years ago

When I config my s3, I get the wrong url call out as

http://mysite.com/elfinder/connector?_token=DE1hdPclHMyBabxoEu46bWIZG1tlorw3J35641yO&cmd=file&target=fls2_RnJvbnRfcGFnZS9tZWRpdGF0aW5nVW5pY29ybi5wbmc

I can upload and see files on my s3 bucket with no problem. The only thing is I can't see the url via my s3 url.

in my config file I have my disk displayed as:

` <?php

return array(

/*
|--------------------------------------------------------------------------
| Upload dir
|--------------------------------------------------------------------------
|
| The dir where to store the images (relative from public)
|
*/
'dir' => [
    'root' => 'media',
    'private' => 'media/user',
],

/*
|--------------------------------------------------------------------------
| Filesystem disks (Flysytem)
|--------------------------------------------------------------------------
|
| Define an array of Filesystem disks, which use Flysystem.
| You can set extra options, example:
|
| 'my-disk' => [
|        'URL' => url('to/disk'),
|        'alias' => 'Local storage',
|    ]
*/
'disks' => env('FILESYSTEM_DRIVER', null),

/*
|--------------------------------------------------------------------------
| Routes group config
|--------------------------------------------------------------------------
|
| The default group settings for the elFinder routes.
|
*/

'route' => [
    'prefix' => 'elfinder',
    'middleware' => 'web', //Set to null to disable middleware filter
],

'resource_url' => 'elfinder',

/*
|--------------------------------------------------------------------------
| Access filter
|--------------------------------------------------------------------------
|
| Filter callback to check the files
|
*/

'access' => 'App\Elfinder\Elfinder::checkAccess',

/*
|--------------------------------------------------------------------------
| Roots
|--------------------------------------------------------------------------
|
| By default, the roots file is LocalFileSystem, with the above public dir.
| If you want custom options, you can set your own roots below.
|
*/

'roots' => null,

/*
|--------------------------------------------------------------------------
| Options
|--------------------------------------------------------------------------
|
| These options are merged, together with 'roots' and passed to the Connector.
| See https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1
|
*/

'options' => array(),

/*
|--------------------------------------------------------------------------
| Root Options
|--------------------------------------------------------------------------
|
| These options are merged, together with every root by default.
| See https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1#root-options
|
*/
'root_options' => array(),

); `

I set up the environment to use local and production filesystems. my filesystem_driver is S3 for production.

I have been trying to figure out where to setup the url, but I can't figure it out. It still throws the connector?token= string.

How do I change the base url for s3 uploads?

noogen commented 5 years ago

There is an issue right now for upload file as public to s3. As a result, everything is uploaded as private. You can't view it unless you create your own controller that redirect to a signed s3 URL.

    public function getTempUrl(Request $request)
    {
        // s3 doesn't like path start with '/'
        $path = trim($request->query('path'), '/');
        $disk = \Storage::disk('s3-public');
        $url  = $disk->temporaryUrl($path, Carbon::now()->addMinutes(5));
        return redirect($url);
    }

    // then route map it
    Route::get('/files/cloud-private', '\Api\Controllers\FileController@getTempUrl');

    // to get this to work with s3, set inside of elfinder.php
    // dir must be empty, because it will conflict with disks URL config later
    'dir' => [],
    'disks' => [
        // this name must match with disk name in the filesystems.php
        's3-disk-name' => [
            'URL' => '/files/cloud-private?path='
        ]
    ,

    // make sure this configuration is correct inside of filesystems.php
   'disks' => [
      // this name must match with elfinder.php
      's3-disk-name' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => 'http://' . env('AWS_BUCKET') . '.s3.' . env('AWS_DEFAULT_REGION') . '.amazonaws.com',
            // elfinder should read this attribute, but it does not
            'visibility' => 'public',
        ]
    ]