This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
storage:s3 [2022/05/24 10:48] – Jan Forman | storage:s3 [2022/05/24 12:28] (current) – Jan Forman | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Amazon S3 compatible service ====== | ||
+ | |||
+ | ===== Public access S3 bucket ===== | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Access by username/ | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | curl --user-agent USERNAME --referer PASSWORD --upload-file " | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | ===== Generate time expiration link ===== | ||
+ | |||
+ | < | ||
+ | <? | ||
+ | |||
+ | if(!function_exists(' | ||
+ | /** | ||
+ | * Calculate the HMAC SHA1 hash of a string. | ||
+ | * | ||
+ | * @param string $key The key to hash against | ||
+ | * @param string $data The data to hash | ||
+ | * @param int $blocksize Optional blocksize | ||
+ | * @return string HMAC SHA1 | ||
+ | */ | ||
+ | function el_crypto_hmacSHA1($key, | ||
+ | if (strlen($key) > $blocksize) $key = pack(' | ||
+ | $key = str_pad($key, | ||
+ | $ipad = str_repeat(chr(0x36), | ||
+ | $opad = str_repeat(chr(0x5c), | ||
+ | $hmac = pack( ' | ||
+ | ($key ^ $opad) . pack( ' | ||
+ | ($key ^ $ipad) . $data | ||
+ | )) | ||
+ | )); | ||
+ | return base64_encode($hmac); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(!function_exists(' | ||
+ | /** | ||
+ | * Create temporary URLs to your protected Amazon S3 files. | ||
+ | * | ||
+ | * @param string $accessKey Your Amazon S3 access key | ||
+ | * @param string $secretKey Your Amazon S3 secret key | ||
+ | * @param string $bucket The bucket (bucket.s3.amazonaws.com) | ||
+ | * @param string $path The target file path | ||
+ | * @param int $expires In minutes | ||
+ | * @return string Temporary Amazon S3 URL | ||
+ | * @see http:// | ||
+ | */ | ||
+ | | ||
+ | function el_s3_getTemporaryLink($accessKey, | ||
+ | // Calculate expiry time | ||
+ | $expires = time() + intval(floatval($expires) * 60); | ||
+ | // Fix the path; encode and sanitize | ||
+ | $path = str_replace(' | ||
+ | // Path for signature starts with the bucket | ||
+ | $signpath = '/' | ||
+ | // S3 friendly string to sign | ||
+ | $signsz = implode(" | ||
+ | // Calculate the hash | ||
+ | $signature = el_crypto_hmacSHA1($secretKey, | ||
+ | // Glue the URL ... | ||
+ | $url = sprintf(' | ||
+ | // ... to the query string ... | ||
+ | $qs = http_build_query($pieces = array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | )); | ||
+ | // ... and return the URL! | ||
+ | return $url.'?' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <?php echo el_s3_getTemporaryLink(' | ||
+ | </ | ||
+ | |||
+ | ===== S3 access using CLI ===== | ||
+ | |||
+ | < | ||
+ | aws configure | ||
+ | aws --endpoint-url=http:// | ||
+ | </ | ||
+ | |||