Magento 2 API : Images are not showing on frontend

by Vaibhav Ahalpara   Last Updated June 28, 2018 06:09 AM

I am using below api for upload images for all store

rest/all/V1/products/".$sku."/media/

but images are not saving for all store.Images are showing in admin only.

here is the code i am using to upload image.

    $path = $this->getImageFilePath($image);
    if (file_exists($path)) {
        $type = pathinfo($path, PATHINFO_EXTENSION);
        $imgContents = file_get_contents($path);
        $base64 = base64_encode($imgContents);
        $data['entry']['media_type']    = 'image';
        $data['entry']['label']         = 'image';
        $data['entry']['position']      = '1';
        $data['entry']['disabled']      = 'false';
        $data['entry']['types']         = array('swatch_image','image','small_image','thumbnail');
        $data['entry']['file']          = $path;
        $data['entry']['Content']['base64EncodedData']     =  $base64;
        $data['entry']['Content']['type']     = "image/jpeg";
        $data['entry']['Content']['name']     = $image;
        $ch = curl_init($this->_url."/rest/all/V1/products/".$sku."/media/");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($this->_token)));
        $products = json_decode(curl_exec($ch),true);
        return $products;
    }
    else
    {
        return "Image does not exist. Path -- ".$path;
    }


Related Questions


Magento 2 : Get image file from custom_option folder

Updated September 25, 2017 15:09 PM



Magento 2 pub/media/catalog folder size too big

Updated May 22, 2017 09:09 AM

Sql query for select all medias in magento 2

Updated September 08, 2018 08:09 AM