mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 05:13:42 -07:00
Merge pull request #9 from AndreyNazarchuk/patch-1
Allow for upload/download from/to memory
This commit is contained in:
commit
0fe3d86781
1 changed files with 23 additions and 9 deletions
32
spaces.php
32
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,15 +286,24 @@ class SpacesConnect {
|
||||||
/*
|
/*
|
||||||
Download a file.
|
Download a file.
|
||||||
*/
|
*/
|
||||||
function DownloadFile($fileName, $destinationPath) {
|
function DownloadFile($fileName, $destinationPath = false) {
|
||||||
try {
|
try {
|
||||||
$result = $this->client->getObject(array(
|
if(!$destinationPath) {
|
||||||
'Bucket' => $this->space,
|
$result = $this->client->getObject(array(
|
||||||
'Key' => $fileName,
|
'Bucket' => $this->space,
|
||||||
'SaveAs' => $destinationPath
|
'Key' => $fileName,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->ObjReturn($result->toArray());
|
return $result['Body'];
|
||||||
|
}else{
|
||||||
|
$result = $this->client->getObject(array(
|
||||||
|
'Bucket' => $this->space,
|
||||||
|
'Key' => $fileName,
|
||||||
|
'SaveAs' => $destinationPath
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this->ObjReturn($result->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (\Exception $e) {
|
catch (\Exception $e) {
|
||||||
$this->HandleAWSException($e);
|
$this->HandleAWSException($e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue