Here is another whay to upload a null (or o Byte) file to S3. I verified this works You can also use the S3 API to upload a file with no body, like so:
aws s3api put-object --bucket "myBucketName" --key "dir-1/my_null_file"
Normally you would specify a --body
blob, but its option and will just add the key as expected. See more on S3 API put-object
The version of AWS CLI tested with is: aws-cli/2.0.4 Python/3.7.5 Windows/10 botocore/2.0.0dev8
Here's how I did it in PHP (even works in outdated 5.4, had to go way back):
// Init an S3Client
$awsConfig = $app->config('aws');
$aws = Aws::factory($awsConfig);
$s3Bucket = $app->config('S3_Bucket');
$s3Client = $aws->get('s3');
// Set null/empty file.
$result = $s3Client->putObject([
'Bucket' => $s3Bucket,
'Key' => "dir-1/my_null_file",
'Body' => '',
'ServerSideEncryption' => 'AES256',
]);
fatal error: An error occurred (404) when calling the HeadObject operation: Key "index.html" does not exist
. – Portraiture