You are here

function _s3fs_cors_file_save in S3 File System CORS Upload 7

Custom version of drupal's file_save() function.

This function exists because we need to call file_save() before saving the file's s3 metadata to the cache. Which means that the filesize() function will fail. So we skip it in this version, since we already know the size.

Parameters

$file: A file object returned by file_load().

Return value

The updated file object.

See also

hook_file_insert()

hook_file_update()

1 call to _s3fs_cors_file_save()
s3fs_cors_upload_value in ./s3fs_cors.module
Value callback for s3fs_cors_upload element type.

File

./s3fs_cors.module, line 642
Allow uploading of files directly to AmazonS3 via the browser using CORS.

Code

function _s3fs_cors_file_save(stdClass $file) {
  module_invoke_all('file_presave', $file);
  module_invoke_all('entity_presave', $file, 'file');
  drupal_write_record('file_managed', $file);

  // Inform modules about the newly added file.
  module_invoke_all('file_insert', $file);
  module_invoke_all('entity_insert', $file, 'file');

  // Clear the static loading cache.
  entity_get_controller('file')
    ->resetCache(array(
    $file->fid,
  ));
  return $file;
}