View of file entities, sorted by upload date, reorders when updating a file I have a view of file entities, sorted by upload date. When I edit one of the fields attached to one of my files the upload date of the file gets updated. The view now shows the last modified file first and no longer the last uploaded. Is this the normal behavior? Is there a way to actually sort my view by upload date?
A quick check with drupal_get_schema() confirms that file entities have only one associated time column called timestamp; there is no separate "upload" and "modified" date. So that timestamp, presumably, gets updated every time the file entity gets saved.

This makes sense from a certain standpoint because editing a file entity could involve updating the file itself.

I decided to take a crack at a custom module that would add a new "upload date" column to the file entity table. This may be completely wrong, and I haven't tested it, so do NOT try to use it on a production website until you're sure it works, but it might just give you what you're looking for.

In mymodule.install:

function mymodule_install() {
  // Add a column to the file table for your new creation date field.
  db_add_field('file_managed', 'upload_date', array(
    'type' =&gt; 'int',
    'unsigned' =&gt; TRUE,
    'not null' =&gt; TRUE,
    'default' =&gt; 0
  ));
  // Load all existing files and set their upload date to be equal to their current timestamp.
  $files = entity_load($file);
  foreach($files as $file) {
    $file-&gt;upload_date = $file-&gt;timestamp;
    file_save($file);
  }
}
// Drop the new field if the module is uninstalled.
function mymodule_uninstall() {
  db_drop_field('file_managed', 'upload_date');
}


In mymodule.module:

// Set the upload time field to the current time when the file is first saved
function mymodule_file_presave($file) {
  if(!isset($file-&gt;upload_date) || $file-&gt;upload_date == 0) {
    $file-&gt;created_date = time();
  }
}
// @TODO make the upload date field editable.


In mymodule.views.inc:

// Add a field handler for your new field.
function mymodule_views_data_alter(&amp;$data) {
  $data['file']['upload_date'] = array(
    'title' =&gt; t("Upload date"),
    'help'  =&gt; t("The date the file was first uploaded."),
    'field' =&gt; array(
      'handler' =&gt; 'views_handler_field_date',
    ),
  );
}


Assuming that I didn't screw up, once the module is installed you'll need to add the upload date field to your view and use it for sorting.