From 88c6b54b52504f335d36e631bf7ed0aa09f228e5 Mon Sep 17 00:00:00 2001 From: andynazay153 Date: Tue, 12 Jun 2018 19:46:33 -0700 Subject: [PATCH 1/2] Allow for upload/download from/to memory Useful if files are accessed rarely and should not be saved to avoid I/O bottleneck --- spaces.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spaces.php b/spaces.php index 806c2a9..9cd6a76 100644 --- a/spaces.php +++ b/spaces.php @@ -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,13 +286,17 @@ 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 )); + + if(!$destinationPath) { + return $result; + } return $this->ObjReturn($result->toArray()); } From 36b4d3005fc188c147c37d9c8dbb85168005c0c1 Mon Sep 17 00:00:00 2001 From: andynazay153 Date: Tue, 12 Jun 2018 19:52:19 -0700 Subject: [PATCH 2/2] Oops Forgot to test changes in your codebase lol --- spaces.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/spaces.php b/spaces.php index 9cd6a76..794e4c6 100644 --- a/spaces.php +++ b/spaces.php @@ -288,17 +288,22 @@ class SpacesConnect { */ function DownloadFile($fileName, $destinationPath = false) { try { - $result = $this->client->getObject(array( - 'Bucket' => $this->space, - 'Key' => $fileName, - 'SaveAs' => $destinationPath - )); - if(!$destinationPath) { - return $result; - } - - return $this->ObjReturn($result->toArray()); + $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);