You are here

private function video_amazon_s3::pushFile in Video 6.4

Same name and namespace in other branches
  1. 6.5 plugins/video_s3/video_s3.lib.inc \video_amazon_s3::pushFile()
1 call to video_amazon_s3::pushFile()
video_amazon_s3::queue in plugins/video_s3/video_s3.lib.inc

File

plugins/video_s3/video_s3.lib.inc, line 227

Class

video_amazon_s3

Code

private function pushFile(stdClass $file) {
  $expires_offset = variable_get('amazon_s3_expires_offset', 604800);
  $perm = variable_get('amazon_s3_private', FALSE) ? AmazonS3::ACL_PRIVATE : AmazonS3::ACL_PUBLIC;
  $cc = variable_get('amazon_s3_cache_control_max_age', 'none');
  $headers = array();
  if ($expires_offset !== 'none') {
    $headers['Expires'] = gmdate('r', $expires_offset == 0 ? 0 : time() + $expires_offset);
  }
  if ($cc !== 'none') {
    $headers['Cache-Control'] = 'max-age=' . $cc;
  }

  // Increase the database timeout to prevent database errors after a long upload
  _video_db_increase_timeout();
  $response = $this->s3
    ->create_object($this->bucket, $file->filepath, array(
    'fileUpload' => $file->filepath,
    'acl' => $perm,
    'contentType' => $file->filemime,
    'headers' => $headers,
  ));
  if ($response
    ->isOK()) {

    // If private, set permissions for Zencoder to read
    if ($perm == AmazonS3::ACL_PRIVATE) {
      $this
        ->setZencoderAccessPolicy($this->bucket, $file->filepath);
    }
    $file->bucket = $this->bucket;
    $s3url = 'http://' . $file->bucket . '.s3.amazonaws.com/' . drupal_urlencode($file->filepath);

    // remove local file
    if (variable_get('amazon_s3_delete_local', FALSE)) {
      $this
        ->replaceLocalFile($file->filepath, $s3url);
    }
    $this
      ->watchdog('Successfully uploaded %file to Amazon S3 location <a href="@s3-url">@s3-path</a> and permission %permission.', array(
      '%file' => $file->filename,
      '@s3-url' => $s3url,
      '@s3-path' => $file->filepath,
      '%permission' => $perm,
    ), WATCHDOG_INFO, $file);
    return $file;
  }
  $this
    ->watchdog('Failed to upload %file to Amazon S3.', array(
    '%file' => $file->filepath,
  ), WATCHDOG_ERROR, $file);
  return NULL;
}