Merge pull request #9 from AndreyNazarchuk/patch-1

Allow for upload/download from/to memory
This commit is contained in:
Devang Srivastava 2018-06-13 08:33:26 +05:30 committed by GitHub
commit 0fe3d86781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -258,11 +258,16 @@ class SpacesConnect {
if($access == "public") {
$access = "public-read";
}
if(!is_file($pathToFile)){
$file = $pathToFile;
}else{
$file = fopen($pathToFile, 'r+');
}
try {
$result = $this->client->putObject(array(
'Bucket' => $this->space,
'Key' => $save_as,
'Body' => fopen($pathToFile, 'r+'),
'Body' => $file,
"ACL" => $access
));
@ -281,15 +286,24 @@ class SpacesConnect {
/*
Download a file.
*/
function DownloadFile($fileName, $destinationPath) {
function DownloadFile($fileName, $destinationPath = false) {
try {
$result = $this->client->getObject(array(
'Bucket' => $this->space,
'Key' => $fileName,
'SaveAs' => $destinationPath
));
return $this->ObjReturn($result->toArray());
if(!$destinationPath) {
$result = $this->client->getObject(array(
'Bucket' => $this->space,
'Key' => $fileName,
));
return $result['Body'];
}else{
$result = $this->client->getObject(array(
'Bucket' => $this->space,
'Key' => $fileName,
'SaveAs' => $destinationPath
));
return $this->ObjReturn($result->toArray());
}
}
catch (\Exception $e) {
$this->HandleAWSException($e);