I have an application that creates a lot of Excel files, which I would like to store in Amazon S3 for later use.
$objPHPExcel = PHPExcel_IOFactory::load('template.xlsx');
$objPHPExcel->getActiveSheet()->getCell('A1')->setValue('SomeVal');
// ...
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('filename.xlsx');
This is the code I usually use to save the files, but I dont't want to store the files on my application server, so I am going to store these in an S3 Bucket.
Here is the code I usually use to upload a file to S3:
$s3 = S3Client::factory(array(
'key' => AWS_KEY,
'secret' => AWS_SECRET
));
$result = $s3->putObject(array(
'Bucket' => AWS_BUCKET,
'Key' => 'somefileinmybucket.jpg',
'SourceFile' => $filepath,
'ACL' => 'private'
));
From my (limited) previous experience with these tools to me the only solution seems to be:
- Save the Excel document to a temporary location on my app server.
- Upload the file to S3 from the temporary location.
- Delete my temporary file.
My question is this: Is there a better way, where I wouldn't have to save it to the disk of my application server in between?
When this process has been initiated, it will be between 50 and 100 excel files that are generated, and should be uploaded to S3, so I'd like to streamline the process as much as possible.
Edit: The question that this could have been a duplicate only deals with S3, not PHPExcel. And it does not discuss PHP, which is what this question deals with.