0

I'm looking for a hacky way to create temporary URLs with Minio

I see on the Laravel docs it says: Generating temporary storage URLs via the temporaryUrl method is not supported when using MinIO.

However from some digging I noticed that I can upload images successfully using:

AWS_ENDPOINT=http://minio:9000

I can't view them because the temporary url is on http://minio:9000/xxx

If I change the AWS endpoint to

AWS_ENDPOINT=http://localhost:9000

The temporary url is on http://localhost:9000/xxx, the signature is validated and the file can be viewed.

The issue exists in this call to make the command. The $command needs to have the host changed but I don't know if I can do that by just passing in an option.

        $command = $this->client->getCommand('GetObject', array_merge([
            'Bucket' => $this->config['bucket'],
            'Key' => $this->prefixer->prefixPath($path),
        ], $options));

There is also the option to just change the baseUrl by providing a temporary_url in the filesystem config. however, because the URL has changed the signature is invalid.

Is there a way I can update the S3Client to use a different host either by passing an option to the getCommand function or by passing a new S3Client to the AWS adapter to use the correct host?

1 Answer 1

2

A very hacky solution I've found is to re-create the AwsS3Adatapter:

      if (is_development()) {
        $manager = app()->make(FilesystemManager::class);
        $adapter = $manager->createS3Driver([
          ...config("filesystems.disks.s3_private"),
          "endpoint" => "http://localhost:9000",
        ]);

        return $adapter->temporaryUrl(
          $this->getPathRelativeToRoot(),
          now()->addMinutes(30)
        );
      }
Sign up to request clarification or add additional context in comments.

3 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
i was hoping for a non hacky way
I ran into the same issue with Laravel’s temporaryUrl() and MinIO that you’re discussing here. To solve it, I built a small package: hosni/laravel-temporary-urls-minio Installation is one line: composer require hosni/laravel-temporary-urls-minio Then just add: 'temporary_url' => env('MINIO_PUBLIC_URL'), to your disk config. After that, everything just works, no need to duplicate the S3 driver or rely on /etc/hosts hacks. Full README: github.com/hosni/laravel-temporary-urls-minio

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.