How To Import Product Images From URL In Magento 2

How To Import Product Images From URL In Magento 2

Magento 2, being popular, often hosts stores migrating from other platforms. It requires to import product images from URL in Magento 2. By default, Magento 2 handles image imports well but they should be located in your server only. But when it comes to importing the product image from an external URL, you can use the below solution.

The below service can be included anywhere required and its execute method will be called with the following params:

  • $product – loaded product instance, the image will be added to it
  • $imageUrl – external image URL
  • $visible – an image will be hidden by default. You may make it visible, simply by passing the boolean value “true”;
  • $imageType – an array, optional param, where you can specify whether to set an image as the main image, a small image or a thumbnail or any combination of those.

The post offers the solution to easily import product images from the external URL in Magento 2 store.

Method To Import Product Images From URL In Magento 2:

Create ImportImageService.php Class in app/code/[Vendor]/[Module]/Service folder and add the following code:

The above solution proves as a time-saver while carrying out the data migration to Magento 2.

Any doubts on the topic can be mentioned in the Comments section below. I’d be happy to help.

Do share the post with fellow developers via social media.

Thank you.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 9 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

2 comments On How To Import Product Images From URL In Magento 2

Leave a reply:

Your email address will not be published.