Custom option with image
I'm new in magento 2. I'm trying to fetch custom options uploaded image.
I have created image upload from customizable options. Here is object that i have printed. I wanted to full image url.
stdClass Object
(
[type] => image/jpeg
[title] => sample_image.jpg
[quote_path] => custom_options/quote/s/a/aKuwRrgMN9Mku3J9QkI5aJfJN9i3p9q4
[order_path] => custom_options/order/s/a/aKuwRrgMN9Mku3J9QkI5aJfJN9i3p9q4
[fullpath] => /xampp/htdocs/pub/media/custom_options/quote/s/a/aKuwRrgMN9Mku3J9QkI5aJfJN9i3p9q4
[size] => 8462
[width] => 275
[height] => 183
[secret_key] => f41cc17e392062a9c669
[url] => stdClass Object
(
[route] => sales/download/downloadCustomOption
[params] => stdClass Object
(
[id] => 2298
[key] => f41cc17e392062a9c669
)
)
)
How can we get 'sample_image.jpg' full path? anyone can help ?
1 Answer 1
Try with below way.
/**
* Get image URL
*
* @return bool|string
* @throws LocalizedException
*/
public function getImageUrl()
{
$url = false;
$image = $this->getImage();
if ($image) {
if (is_string($image)) {
$uploader = $this->uploaderPool->getUploader('image');
$url = $uploader->getBaseUrl().$uploader->getBasePath().$image;
} else {
throw new LocalizedException(
__('Something went wrong while getting the image url.')
);
}
}
return $url;
}
I hope it helps!
answered Mar 12, 2019 at 13:35
Chirag Patel
6,1662 gold badges26 silver badges66 bronze badges
-
Hello Chirag, Thanks for response. I tried your code but but i'm new in magento 2 and don't know how to use '$this->uploaderPool'. For your information i have created my custom module and trying to fetch image path from order_items. So can you please suggest how i can use $this->uploaderPool? code reference will be good. ThanksAjay Gohel– Ajay Gohel2019年03月13日 14:30:26 +00:00Commented Mar 13, 2019 at 14:30
default