Skip to content

Commit bcf5e55

Browse files
committed
fix for preview image logic
1 parent 7d92203 commit bcf5e55

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Controller/Adminhtml/Ajax/UpdateAdminImage.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,27 @@ public function execute()
107107
$cleanUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'];
108108
$baseUrl = $this->storeManager->getStore()->getBaseUrl();
109109
$relativePath = str_replace($baseUrl, '', $cleanUrl);
110-
110+
111+
// file id can be media/wmpvownqus8xwvylswsr_1
112+
111113
// Check if this is a Cloudinary rendition path
112114
if (strpos($relativePath, '.renditions/cloudinary/') !== false) {
113115
// Extract the filename from the renditions path
114116
$parts = explode('.renditions/cloudinary/', $relativePath);
115117
$filename = end($parts);
116-
118+
117119
// Remove the first cld_ prefix if there are multiple
118120
// e.g., cld_68b6aa57b4d59_cld_6458c4355ee79_cld-sample-2.jpg -> cld_6458c4355ee79_cld-sample-2.jpg
119-
if (preg_match('/^cld_[a-z0-9]+_cld_/', $filename)) {
121+
if (preg_match('/^cld_[a-z0-9]+_/', $filename)) {
120122
$filename = preg_replace('/^cld_[a-z0-9]+_/', '', $filename);
121123
}
122-
124+
123125
// The public ID should be media/filename for Cloudinary
124126
$filedId = 'media/' . $filename;
125127
} else {
126128
// For regular media files, use the relative path as is
127129
$filedId = $relativePath;
128-
130+
129131
// Remove media/ prefix if present (it will be in the public ID already)
130132
if (strpos($filedId, 'media/') === 0) {
131133
$filedId = substr($filedId, 6);

0 commit comments

Comments
 (0)