Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use private disks #54

Closed
milewski opened this issue Sep 5, 2022 · 1 comment
Closed

Add ability to use private disks #54

milewski opened this issue Sep 5, 2022 · 1 comment

Comments

@milewski
Copy link
Contributor

milewski commented Sep 5, 2022

Hi currently it's impossible to use private cloud disks.. for instance, this is how it is used with default nova image/file fields:

Image::make('Image', 'image->file')
    ->storeOriginalName('image->filename')
    ->disk('s3-private')
    ->preview(fn (string $file, string $disk) => Storage::disk($disk)->temporaryUrl($file, now()->addMinute()))
    ->thumbnail(fn (string $file, string $disk) => Storage::disk($disk)->temporaryUrl($file, now()->addMinute()))
    ->creationRules('required')
    ->updateRules('nullable'),

Here is a quickly docker-compose snipped to start a "local s3" if this helps develop this feature

  minio:
    image: bitnami/minio:2022
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=secret-password
      - MINIO_DEFAULT_BUCKETS=development-public:public,development-private:none
@crezra
Copy link
Collaborator

crezra commented Sep 8, 2022

Hi 👋

Thank you for reporting this, we have added a new method to give the ability to have more control over the entity's urls, you may use the resolveUrlUsing method to build your urls on the fly based on the currently selected disk for the corresponding asset on said disk.

FileManager::make('Avatar', 'avatar')
    ->limit(5)
    ->resolveUrlUsing(function (NovaRequest $request, string $path, string $disk, Filesystem $filesystem) {
        if ($disk === 's3-private') {
            return $filesystem->temporaryUrl($path, now()->addMinutes(5));
        }

        return $filesystem->url($path);
    })
    ->multiple(),

This will be included in the next release, but you can checkout main to test it and please do let us know if you're encountering issues.

All the best !

@crezra crezra closed this as completed Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants