Drupal 7 Form API file field - not recognizing the imported file function test_data_import_form($form, &amp;$form_state) {
    $form = array();

    //$form['#attributes'] = array('enctype' =&gt; 'multipart/form-data');

    $form['import_data'] = array(
        '#type' =&gt; 'file',
        '#title' =&gt; t('Upload data file'),
        '#size' =&gt; 22,
        '#required' =&gt; TRUE,
    );

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Submit'),
        '#validate' =&gt; array('test_data_import_validate'),
        '#submit' =&gt; array('test_data_import_submit'),
    );

    return $form;
}


Please see my form code above. I am trying to import a file through this form, but the file I am trying to import is not recognized as it is throwing "Required field error". Please help me with this.
I tried #file_managed instead of the file, and then I am able to upload the files into the application. But, this option stores the file in managed_file table in the database with a temporary storage. 
The file details are not visible in the dsm() (devel module).