title: Re-processing attached images in drupal 7
body: <p>I'm trying to import nodes from my forum to drupal 7. Not in bulk, but one by one so that news posts can be created and referenced back to the forum. The kicker is that I'm wanting to bring image attachments across as well...</p>
  
  <p>So far, using the code example here <a href="http://drupal.org/node/889058#comment-3709802" rel="nofollow">http://drupal.org/node/889058#comment-3709802</a> things mostly work: Nodes are created, but the images don't go through any validation or processing.</p>
  
  <p>I'd like the attached images to be validated against the rules defined in the content type. in particular the style associated with my image field which resizes them to 600x600.</p>
  
  <p>So, instead of simply creating the nodes programatically with my own form, i decided to <em>modify</em> a "new" node using hook_node_prepare and using the existing form to create new content (based on passed in url args). This works really well and a create form is presented pre-filled with all my data. including the image! very cute.</p>
  
  <p>I expected that i could then hit <em>preview</em> or <em>save</em> and all the validation and resizing would happen to my image, but instead i get the error: </p>
  
  <pre><code>"The file used in the Image field may not be referenced."
  </code></pre>
  
  <p>The reason for this is that my file doesn't have an entry in the file_usage table.. *le sigh*</p>
  
  <p>so, how do i get to all the nice validation and processing which happens when i manually choose a file to upload? like resizing, an entry in the file_usage table.</p>
  
  <p>The ajax upload function does it, but i can't find the code which is called to do this anywhere in the api.</p>
  
  <p>What file upload / validation functions does Drupal call which i'm not doing?</p>
  
  <p>Anybody have any experience with the file/image api for Drupal 7 who can help me out?</p>