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:
andynazay153 2018-06-12 19:46:33 -07:00 committed by GitHub
parent 26d1b68f84
commit 88c6b54b52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,13 +286,17 @@ 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,
'Key' => $fileName, 'Key' => $fileName,
'SaveAs' => $destinationPath 'SaveAs' => $destinationPath
)); ));
if(!$destinationPath) {
return $result;
}
return $this->ObjReturn($result->toArray()); return $this->ObjReturn($result->toArray());
} }