Reputation: 57
This is probably a simple question for some, but I couldn't find answers online.
try {
$result = $s3->putObject([
'Bucket' => $bucketName,
'Key' => 'place/',
'Body' => fopen("place/***everything in here***", 'r'),
//'ACL' => 'public-read',
]);
}
Is this even possible? Otherwise, I can just make a foreach loop or something like that. If anyone has any ideas, that would be great.
Upvotes: 0
Views: 789
Reputation: 270144
The Amazon S3 PutObject()
API call can only upload one file at a time.
If you wish to upload multiple files, loop through the files and upload each of them with PutObject()
.
To make the process run faster, you can make the API calls in parallel to take full advantage of available bandwidth.
Please note that you can also refer to file while uploading, rather than having to supply the contents of the file via the body
parameter. See: Simplest way to upload a file to AWS S3 via PHP | by Kent Aguilar | Medium
You might also prefer using the AWS Command-Line Interface (CLI). It has two commands that can upload a directory of files:
aws s3 cp --recursive
(to copy a tree of directories)aws s3 sync
to synchronize files (only copying new/changed files)Upvotes: 2