You are here

function amazons3_upload_location in AmazonS3 7.2

Return a URI for use in an #upload_location or similar form element.

Parameters

string $uri_scheme: The scheme to use for the URI.

string $bucket: (optional) bucket, if the URI is an s3 URI.

string $file_directory: (optional) File directory for the URI.

array $data: (optional) Array of data to use when replacing tokens.

Return value

string A fully-qualified string URI.

2 calls to amazons3_upload_location()
amazons3_field_widget_uri in ./amazons3.module
Return the destination URI for a file field.
amazons3_file_entity_upload_destination_uri_alter in ./amazons3.module
Implements hook_file_entity_upload_destination_uri_alter().

File

./amazons3.module, line 438
Hook implementations for the AmazonS3 module.

Code

function amazons3_upload_location($uri_scheme, $bucket = NULL, $file_directory = NULL, array $data = array()) {
  if ($uri_scheme == 's3') {
    $destination = $bucket;

    // If no bucket is specified, but this is an S3 URI, use the default bucket.
    if (empty($destination)) {
      $config = StreamWrapperConfiguration::fromDrupalVariables();
      $destination = $config
        ->getBucket();
    }
    if (!empty($file_directory)) {
      $destination .= '/' . trim($file_directory, '/');
    }
  }
  else {
    $destination = trim($file_directory, '/');
  }

  // Replace tokens.
  $destination = token_replace($destination, $data);
  return $uri_scheme . '://' . $destination;
}