-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
ImageResizer clobbers query string on URLs to resized images #812
Comments
What does your filesystem disk configuration look like along with the configuration for your CMS file folders? |
Did you checked the source code I mentioned ? Here is my plugin code: <?php namespace My\Plugin\Models;
class Comment extends Model
{
public $attachOne = [
'image' => [
'System\Models\File',
'public' => false,
'disk' => 's3',
],
];
} // Tested, all got correct URL!
url($comment->image->path); // ✅
url($comment->image->getThumb(400, 400)); // ✅ But this is bad: (source) use System\Classes\ImageResizer;
// Got wrong encoded URL
ImageResizer::filterGetUrl($comment->image, 40, 40); // 👎🏼 Furthermore, I also tested upload files to media manager. Everything is OK. And here is how my config looks like: <?php
// config/cms.php
return [
'storage' => [
'uploads' => [
'disk' => 's3',
'folder' => 'dev/uploads',
'path' => 'https://my-bucket.s3.amazonaws.com/dev/uploads',
'temporaryUrlTTL' => 3600,
],
'media' => [
'disk' => 's3',
'folder' => 'dev/media',
'path' => 'https://my-bucket.s3.amazonaws.com/dev/media',
],
'resized' => [
'disk' => 's3',
'folder' => 'dev/resized',
'path' => 'https://my-bucket.s3.amazonaws.com/dev/resized',
],
],
]; <?php
// config/filesystems.php
return [
'default' => 's3',
'disks' => [
's3' => [
'bucket' => 'my-bucket',
'driver' => 's3',
'endpoint' => null,
'key' => 'AKI..................2A',
'region' => 'ap-northeast-1',
'secret' => 'Fxt49.............8TE',
'stream_uploads' => false,
'url' => 'https://my-bucket.s3.amazonaws.com/',
'use_path_style_endpoint' => false,
],
],
]; |
WorkaroundCurrently I will solve this problem by adding custom list column to replace the image resize function. class Plugin extends PluginBase
{
public function registerListColumnTypes()
{
return [
'thumbnail' => function ($value, $column, $record) {
$image = null;
$config = $column->config;
// Get config options with defaults
$width = isset($config['width']) ? $config['width'] : 50;
$height = isset($config['height']) ? $config['height'] : 50;
$options = isset($config['options']) ? $config['options'] : [];
$fallback = isset($config['default']) ? $config['default'] : null;
// Handle attachMany relationships
if (isset($record->attachMany[$column->columnName])) {
$image = $value->first();
// Handle attachOne relationships
} elseif (isset($record->attachOne[$column->columnName])) {
$image = $value;
// Handle absolute URLs
} elseif (str_contains($value, '://')) {
$image = $value;
// Handle embedded data URLs
} elseif (starts_with($value, 'data:image')) {
$image = $value;
// Assume all other values to be from the media library
} elseif (!empty($value)) {
$image = MediaLibrary::url($value);
}
if (!$image && $fallback) {
$image = $fallback;
}
if ($image) {
// $imageUrl = ImageResizer::filterGetUrl($image, $width, $height, $options);
// 🔥 KEY POINT: replace to this:
$imageUrl = $value->getThumb($width, $height, $options);
return "<img src='$imageUrl' width='$width' height='$height' />";
}
},
];
}
} columns:
# ...
image:
label: image
type: thumbnail
options:
mode: crop |
@lackneets can you try replacing the problem lines in ImageResizer.php with the following: // Ensure that a properly encoded URL is returned
$url = \Winter\Storm\Router\UrlGenerator::buildUrl($url); |
@lackneets are you able to test my proposed fix? If it works I can merge it. Otherwise it'll have to wait until I or someone else can reproduce the original issue and test the fix. |
Winter CMS Build
1.2
PHP Version
8.1
Database engine
SQLite
Plugins installed
No response
Issue description
My project is configured to store file on s3. And I set a image type column in backend list, but it cannot display correctly.
Steps to replicate
At this line, I figure out the access token (query string) which is after filename has been url-encoded as below:
It should be:
I understand a filename without url-encode is unsafe, however it should be optimized for AWS s3 file access. Perhaps to split out query string before encode it.
Workaround
No response
The text was updated successfully, but these errors were encountered: