How to save file uploaded with plupload integration module, and make it managed? As described here, I can use Plupload integration module to upload my files to server. They go there, I can see them in temp directory, and that's the point I'm stuck.

Code I'm using for a field is:

'DownloadFile' =&gt; array(
  '#title' =&gt; t("Download's download"),
  '#title_display' =&gt; 'invisible',
  '#type' =&gt; 'file',

  '#upload_validators' =&gt; array(
    'file_validate_extensions' =&gt; array( /* extensions */ ),
    'file_validate_size' =&gt; array(variable_get('max_size', 300 * 1024 * 1024)),
  ),
  '#upload_location' =&gt; 'public://mymodule/download',
  '#plupload_settings' =&gt; array(
    'runtimes' =&gt; 'html5',
    'chunk_size' =&gt; '10mb',
    'max_file_size' =&gt; variable_get('max_size', 300 * 1024 * 1024) . 'b',
  ),
),


In form validation function I get thus in $form_state['values']:



Since the Views for Drupal 7 got reasonably stable, I was using Drupal 7 and managed files. I have literally no idea how should I take this file and plug it into managed table for other functions to use. As you can see from the time difference, it been some time between the moment I was able to upload and now - all this time with no idea. Tried to treat it as '#type' =&gt; 'file', but functions for unmanaged don't get it. They require specific name and even if I add '#name' to plupload form element, it still fails.

Is there any way to add file to managed table knowing it's location in temporary://?
I didn't really checked all links in this email but I have used Plupload very extensively and worked very well. 

&lt;?php 


  $form['upload'] = array(
    '#type' =&gt; 'plupload',
    '#title' =&gt; '',
    '#description' =&gt; t('Maximum file size allowed: 10MB'),
    '#upload_validators' =&gt; array(
      'file_validate_extensions' =&gt; array('zip rar 7z odt doc docx xls xlsx png jpg pdf rtf txt'),
    ),
    '#plupload_settings' =&gt; array(
        'runtimes' =&gt; 'html5,flash', // Also consider the order of technologies.
        'chunk_size' =&gt; '10mb',
        'unique_names' =&gt; TRUE,
        'flash_swf_url' =&gt; file_create_url(_plupload_library_path() . '/js/plupload.flash.swf'),
      ),
    );


  return $form;


  // Submit handler:
  //function ..._submit($form, &amp;$form_state) {
  if (!empty($form_state['values']['upload'])) {
    $form_state['uploaded_files'] = quotes_file_save_files($form_state['values']['upload']);
  }

  // }


function quotes_file_save_files($files) {
  $saved_files = array();
  $scheme = 'private://'; // Change to "public://" if you want to move to public files folder.
  foreach ($files as $uploaded_file) {
    if ($uploaded_file['status'] == 'done') {
      $source = $uploaded_file['tmppath'];
      $destination = file_stream_wrapper_uri_normalize($scheme . $uploaded_file['name']);
      $destination = file_unmanaged_move($source, $destination, FILE_EXISTS_RENAME);
      $file = plupload_file_uri_to_object($destination);
      file_save($file);
      // Check the $file object to see if all necessary properties are set. Otherwise, use file_load($file-&gt;fid) to populate all of them.
      // $file = file_load($file-&gt;fid);
      $saved_files[] = $file;
    }
  }

  return $saved_files;
}


?&gt;


I think the point is, plupload does not save the files to the managed files folder by default, but populates all the data in the $form_state array for you to process and save. 

Edit: In relation to the other answer that mentions file object's status should be permanent. I'm sure you already know that the status must be 1. But plupload_file_uri_to_object function sets the $file object's status to 1, so it's not done in the example. 

Good luck!