Upload image to commerce product on save? Currently working with the Commerce module in Drupal 7. 

I've hooked the product creation form (using hook_form_alter()) to include a custom validation function. I have an image for each product that is generated on the fly and needs to be associated with the relevant product. The name of the image field is 'field_pchem_structure_image.'

I'm able to create and save the image, but I need to make sure it is added to the product when the product is saved. I've tried setting:

$form_state['values']['field_pchem_structure_image'] = $file; 

However, this does not seem to work. Could someone please explain how to do this?
I installed Commerce Customizable Products and created a new line item type. This enabled me to create another product type with an upload field in the add to cart form users can use to upload file to the site. Also use rules obviously to do some more backend stuff, like change file location (that's set with a token uid) to be updated on username change and lots more. Can do lots of fun stuff with media/file entity, but your fix also works, just adding this for the search bot arena ;)