how to upload an image of product in drupal commerce I would like to upload an image of product in drupal commerce programmatically while creating a product, Here is my code for create product, but drupal return error said 

Call to a member function set() on a non-object in &lt;b&gt;C:\xampp\htdocs\mySite\sites\all\modules\api\mymodule.inc


any suggestion is greatly appreciated.

Thanks 

mymodule.inc

$wrapper = entity_metadata_wrapper('commerce_product', commerce_product_new('product'));
$properties = entity_get_property_info('commerce_product');

$wrapper-&gt;title = $title;
$wrapper-&gt;sku = $sku;
$wrapper-&gt;commerce_price-&gt;amount = $price;    // Price in minors units 500 = 5$
$wrapper-&gt;commerce_price-&gt;currency_code = 'MMK';
$wrapper-&gt;cmp_store = 2;
//$wrapper-&gt;field_category = 137;
$wrapper-&gt;field_product_color = 106;

$file_path = file_save_data(file_get_contents('C:\\Users\\ASUSS\\Desktop\\Nexus_5_(1).jpg'), 'public://products/Nexus_5_(2).jpg');
$wrapper-&gt;field_product_image-&gt;file-&gt;set($file_path);

try{
    $wrapper-&gt;save();
    $result = "success!" ;
}catch(Exception $ex){
    $result = "not success! -&gt; ". $ex;
}
Finally, I found the way, field_product_image can only accept array value. Here is my code, 

function commerce_services_product_create($data, $flatten_fields) {
    $status =1;
    $commerce_price = array();

    $sku = $data['sku'];
    $title = $data['title'];
    $type = $data['type'];
    $commerce_price = $data['commerce_price'];
    $price = $commerce_price['amount'];

    $wrapper = entity_metadata_wrapper('commerce_product',  commerce_product_new('product'));
    $properties = entity_get_property_info('commerce_product');

    $wrapper-&gt;title = $title;
    $wrapper-&gt;sku = $sku;
    $wrapper-&gt;commerce_price-&gt;amount = $price;    // Price in minors units 500 = 5$
    $wrapper-&gt;commerce_price-&gt;currency_code = 'MMK';
    $wrapper-&gt;cmp_store = 2;
    $wrapper-&gt;field_product_color = 106;

    $file = file_save_data(file_get_contents('C:\\Users\\ASUSS\\Desktop\\Nexus_5_(1).jpg'), 'public://products/Nexus_5_(2).jpg');
    $image_val = array(
        array(
            'fid' =&gt; $file-&gt;fid,
            'title' =&gt; $file-&gt;filename,
            'filename' =&gt; $file-&gt;filename,
            'filepath' =&gt; $file-&gt;filepath,
            'filesize' =&gt; $file-&gt;filesize
        ),
    );

    $wrapper-&gt;field_product_image = $image_val;

    try{
        $wrapper-&gt;save();
        $result = "success!" ;
    }catch(Exception $ex){
        $result = "not success! -&gt; ". $ex;
    }

    $reply= (array('status' =&gt; $status,'result' =&gt; $result) );
    return $reply;
}


Thanks,