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") {
|
if($access == "public") {
|
||||||
$access = "public-read";
|
$access = "public-read";
|
||||||
}
|
}
|
||||||
|
if(!is_file($pathToFile)){
|
||||||
|
$file = $pathToFile;
|
||||||
|
}else{
|
||||||
|
$file = fopen($pathToFile, 'r+');
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$result = $this->client->putObject(array(
|
$result = $this->client->putObject(array(
|
||||||
'Bucket' => $this->space,
|
'Bucket' => $this->space,
|
||||||
'Key' => $save_as,
|
'Key' => $save_as,
|
||||||
'Body' => fopen($pathToFile, 'r+'),
|
'Body' => $file,
|
||||||
"ACL" => $access
|
"ACL" => $access
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -281,7 +286,7 @@ class SpacesConnect {
|
||||||
/*
|
/*
|
||||||
Download a file.
|
Download a file.
|
||||||
*/
|
*/
|
||||||
function DownloadFile($fileName, $destinationPath) {
|
function DownloadFile($fileName, $destinationPath = false) {
|
||||||
try {
|
try {
|
||||||
$result = $this->client->getObject(array(
|
$result = $this->client->getObject(array(
|
||||||
'Bucket' => $this->space,
|
'Bucket' => $this->space,
|
||||||
|
@ -289,6 +294,10 @@ class SpacesConnect {
|
||||||
'SaveAs' => $destinationPath
|
'SaveAs' => $destinationPath
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if(!$destinationPath) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->ObjReturn($result->toArray());
|
return $this->ObjReturn($result->toArray());
|
||||||
}
|
}
|
||||||
catch (\Exception $e) {
|
catch (\Exception $e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue