mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-07-13 08:33:12 -07:00
Allow for upload/download from/to memory
Useful if files are accessed rarely and should not be saved to avoid I/O bottleneck
This commit is contained in:
parent
26d1b68f84
commit
88c6b54b52
1 changed files with 11 additions and 2 deletions
13
spaces.php
13
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,7 +286,7 @@ class SpacesConnect {
|
|||
/*
|
||||
Download a file.
|
||||
*/
|
||||
function DownloadFile($fileName, $destinationPath) {
|
||||
function DownloadFile($fileName, $destinationPath = false) {
|
||||
try {
|
||||
$result = $this->client->getObject(array(
|
||||
'Bucket' => $this->space,
|
||||
|
@ -289,6 +294,10 @@ class SpacesConnect {
|
|||
'SaveAs' => $destinationPath
|
||||
));
|
||||
|
||||
if(!$destinationPath) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $this->ObjReturn($result->toArray());
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue