mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 13:23:47 -07:00
Merge pull request #14 from markruys/master
Support content type for UploadFile()
This commit is contained in:
commit
22880123ef
1 changed files with 12 additions and 26 deletions
38
spaces.php
38
spaces.php
|
@ -252,7 +252,7 @@ class SpacesConnect {
|
||||||
/*
|
/*
|
||||||
Upload a file.
|
Upload a file.
|
||||||
*/
|
*/
|
||||||
function UploadFile($pathToFile, $access = "private", $save_as = "") {
|
function UploadFile($pathToFile, $access = "private", $save_as = "", $mime_type = "application/octet-stream") {
|
||||||
if(empty($save_as)) {
|
if(empty($save_as)) {
|
||||||
$save_as = $pathToFile;
|
$save_as = $pathToFile;
|
||||||
}
|
}
|
||||||
|
@ -266,10 +266,11 @@ class SpacesConnect {
|
||||||
}
|
}
|
||||||
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' => $file,
|
'Body' => $file,
|
||||||
"ACL" => $access
|
'ACL' => $access,
|
||||||
|
'ContentType' => $mime_type
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->client->waitUntil('ObjectExists', array(
|
$this->client->waitUntil('ObjectExists', array(
|
||||||
|
@ -433,27 +434,12 @@ class SpacesConnect {
|
||||||
Creates a temporary URL for a file (Mainly for accessing private files).
|
Creates a temporary URL for a file (Mainly for accessing private files).
|
||||||
*/
|
*/
|
||||||
function CreateTemporaryURL($file_name = "", $valid_for = "1 hour") {
|
function CreateTemporaryURL($file_name = "", $valid_for = "1 hour") {
|
||||||
$secret_key = $this->secret_key;
|
$cmd = $this->client->getCommand('GetObject', [
|
||||||
$expiry = strtotime("+ ".$valid_for);
|
'Bucket' => $this->space,
|
||||||
$file_name = rawurlencode($file_name);
|
'Key' => $file_name
|
||||||
$file = str_replace(array('%2F', '%2B'), array('/', '+'), ltrim($file_name, '/') );
|
]);
|
||||||
$objectPathForSignature = '/'. $this->space .'/'. $file_name;
|
$request = $this->client->createPresignedRequest($cmd, $valid_for);
|
||||||
$stringToSign = implode("\n", $pieces = array('GET', null, null, $expiry, $objectPathForSignature));
|
return (string)$request->getUri();
|
||||||
$url = 'https://' . $this->space . '.'.$this->region.'.'.$this->host.'/' . $file_name;
|
|
||||||
$blocksize = 64;
|
|
||||||
if (strlen($secret_key) > $blocksize) $secret_key = pack('H*', sha1($secret_key));
|
|
||||||
$secret_key = str_pad($secret_key, $blocksize, chr(0x00));
|
|
||||||
$ipad = str_repeat(chr(0x36), $blocksize);
|
|
||||||
$opad = str_repeat(chr(0x5c), $blocksize);
|
|
||||||
$hmac = pack( 'H*', sha1(($secret_key ^ $opad) . pack( 'H*', sha1(($secret_key ^ $ipad) . $stringToSign))));
|
|
||||||
$signature = base64_encode($hmac);
|
|
||||||
$queries = http_build_query($pieces = array(
|
|
||||||
'AWSAccessKeyId' => $this->access_key,
|
|
||||||
'Expires' => $expiry,
|
|
||||||
'Signature' => $signature,
|
|
||||||
));
|
|
||||||
$url .= "?".$queries;
|
|
||||||
return $this->ObjReturn($url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue