When not working with products, is there a magento2 model/function that can be used for reading/writing images to the media folder? (like addImageToMediaGallery / getMediaGalleryProcessor()->addImage used when working with products).

I've made a module that loads data from an api/json link into to a custom table where one column is an image URL. I wan't to save the image from the link to the local media folder.

I know I can do this with PHP (file_put_contents, fwrite, curl), but I'm thinking there must be a "Magento way" to do this?

I get the image url by $image = $this->myRepository->getImageUrl($data['image_url']);

1 Answer 1


Solved it.

I just used Magento\Framework\Filesystem\Io\File; and $this->file->read($originalImageUrl, $newImage);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.