GautamD31
GautamD31

Reputation: 28763

How to upload a folder into AWS

Iam using AWS to upload images, css and some zip files for my site and they are fine to upload them.But now I want like I first upload a zip on localhost and I will extract them into one folder and I want to upload that entire folder into aws.Can anyone help me to do it.Thanks in advance.

Iam using function to upload files like

require_once 'aws-sdk-for-php/sdk.class.php';
$s3 = new AmazonS3();
$response = $s3->create_object($bucket, $filename, array(
'fileUpload' => $filepath,
 'acl' => AmazonS3::ACL_PUBLIC,
'storage' => AmazonS3::STORAGE_REDUCED,
'headers' => array(
    'Cache-Control'    => 'max-age=2592000'
);

It is working fine for single images.But I dont know how to do it for entore folder.

Upvotes: 1

Views: 380

Answers (2)

Marcelo Agimóvel
Marcelo Agimóvel

Reputation: 1719

Using PHP you can upload entire directory:

$client->uploadDirectory(
  SOURCE_FOLDER,
  YOUR_BUCKET_NAME,
  DESTINATION,
  array(
    'concurrency' => 5,
    'debug'          => TRUE,
    'force'            => FALSE,
    'params'        => array(
      'ServerSideEncryption' => 'AES256',
    ),
  )
);

Upvotes: 0

John Rotenstein
John Rotenstein

Reputation: 269101

There is no API call for Amazon S3 that can upload an entire folder. You can loop through your list of local files and then upload each individually to S3. If you're capable, doing it in parallel can greatly speed the upload, too.

You could also cheat by calling out to the AWS Command Line Interface (CLI). The CLI can upload/download a recursive list of files and can also do multi-part upload for large files. There is also an aws s3 sync command that can intelligently upload only new/modified files.

Upvotes: 1

Related Questions