yii2tech / file-storage

This package has been abandoned. See: https://www.patreon.com/posts/59332556
Other
119 stars 30 forks source link

Cant download file from amazon storage using bucket's fileSubDirTemplate option #23

Closed phrakon closed 4 years ago

phrakon commented 4 years ago

What steps will reproduce the problem?

Try to open file 08c699d1d76c228daf06f93f8e04c185.jpg using DownloadAction.

My fileStorage config is:

'fileStorage' => [
            '__class' => \common\components\filestorage\yandex\Storage::class,
            'buckets' => [
                '***' => [
                    'acl' => 'public-read',
                    'fileSubDirTemplate' => '{^name}/{^^name}/{^^^name}',
                ],
            ],
        ],

What is the expected result?

No error.

What do you get instead?

Client error: GET https://****.storage.yandexcloud.net/08c699d1d76c228daf06f93f8e04c185.jpg resulted in a 404 Not Found

Additional info

if i put '0/8/c/08c699d1d76c228daf06f93f8e04c185.jpg', then https://github.com/yii2tech/file-storage/blob/5cf882e6341587861933365deedbe7bda06af280/src/DownloadAction.php#L103 tells that file not found, so that filename must be without ^name segments

i think https://github.com/yii2tech/file-storage/blob/5cf882e6341587861933365deedbe7bda06af280/src/amazon/Bucket.php#L514 should be $streamPath = 's3://' . $this->getUrlName() . '/' . $this->getFullFileName($fileName); anyway it fixes the error

Q A
This Package Version 1.?.?
Yii Framework Version 2.0.?
File Storage Type amazon
PHP version
Operating system
phrakon commented 4 years ago

I use my own implementation for yandex cloud s3 (compatible with amazon) based on yours. But it has no sense. It is about 99% your code except endpoint, region and so on.

klimov-paul commented 4 years ago

No, the original code of DownloadAction it correct: the $filename argument should contain any sub-folder for the file already, including the subDirTemplate. So download requests for file logo.png and images/logo.png will be different.

You should use getFullFileName() to create an argument for the DownloadAction URL.