Moving or copying your files to Amazon S3

Last updated on
22 February 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

When moving to Filebrowser 7.x-3.x to use the Amazon S3 service, you might want to copy or move the files and directories on your server to Amazon S3.

You can use the Amazon Command Line Interface to do so.
Instruction to install your AWS CLI client can be found here.

After installation and configuration you can copy a directory on your server to S3:
$ aws s3 cp path/to/a_folder s3://name_of_bucket/key --recursive

In your Filebrowser node change the field "folder path" to

"s3://name_of_bucket/key"

Script to add files in S3 bucket folder and add files on new location
************************************************************
try {
$config = _s3fs_get_config();
$s3 = _s3fs_get_amazons3_client($config);
}
catch (S3fsException $e) {
form_set_error('form', $e->getMessage());
return FALSE;
}

$result = $s3->putObject(array(
'Bucket' => 'Bucket-name',
'Key' => $folderpath, // example 'newfolder/acb' which you need to create on S3
'SourceFile' => $path . '/' . $filename, // drupal real path of files.
));
$result = $s3->putObject(array(
'ACL' => 'public-read', //access controle
'Bucket' => 'Bucket-name',
'Key' => $folderpath.'/' . $filename,
'SourceFile' => $path . '/' . $filename,
));
****************************************************************************

Help improve this page

Page status: No known problems

You can: