1

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 ?

asked Mar 12, 2019 at 13:22

1 Answer 1

0

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
1
  • 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. Thanks Commented Mar 13, 2019 at 14:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.