addImageToMediaGallery找不到图像

I am trying to get products to be loaded from an XML file and imported into Magento 2.

The code is working perfectly, except if I try to add addImageToMediaGallery which adds images to the gallery. It will return the error "The image does not exist". I have tried making the base path start with './media', i tried '/media', i tried './pub/media', even 'domain.com/media' but none of them are working.

If I navigate to the URL myself, it is definitely loading the image.

        $imageBasePath = '/media/glasses_pic2/';
        //$imagePath = $imageBasePath . $productData['Articelnumberer'][0]; // path of the image
        $imagePath = $path;
        try {
            $_product->addImageToMediaGallery($imageBasePath . strtolower($productData['Articelnumberer']) .'.jpg', array('image', 'small_image', 'thumbnail'), false, false);
        } catch (Exception $e) {
            echo 'Error adding image: '. $e->getMessage() . ' - Location: '. $imageBasePath . strtolower($productData['Articelnumberer']) .'.jpg';
            continue;
        }

From what iv googled and researched, this is how it should be done, but it is just always returning that error.