In php, I want to upload the s3 file to the browser without saving it to my server

I have files on Amazon S3. They are called with a unique identifier, so there are no duplicates. I access them using the allowed URL. I need to transfer them to the browser, but I need to rename them. I am using fopen right now, but it uploads the file to my server before sending the file to the browser. How can I transfer files to my server in a browser? Or how can I upload a download - uploading a small piece to my server and passing this to the browser when the next fragment is downloaded?

Also - I would really like to use CloudFront, but they do not offer authenticated URLs. I believe that I can use CURL to send credentials for the request - can I make this “pass” file serving CURL?

Thanks!

+5
source share
3 answers

, S3, , . ? , S3 -URL . , , , , S3 URL , , .

, PHP:


:

, " " , URL-. : .

// I'm only implementing the parts required for GET requests.
// POST uploads will require additional components.
function getStringToSign($req, $expires, $uri) {
   return "$req\n\n\n$expires\n$uri";
}

function encodeSignature($sig, $key) {
    $sig = utf8_encode($sig);
    $sig = hash_hmac('sha1', $sig, $key);
    $sig = base64_encode($sig);
    return urlencode($sig);
}

$expires = strtotime('+1 hour');
$stringToSign = getStringToSign('GET', $expires, $uri);
$signature = encodeSignature($stringToSign, $awsKey);

$url .= '?AWSAccessKeyId='.$awsKeyId
       .'&Expires='.$expires
       .'&Signature='.$signature;

$url, . (sha1), , AWS .

+5

http_get, request_options, httpauth httpauthtype? , , .

, MIME .

+1

readfile ( " http://username:password@host/filename.ext" )?

outputbuffer, , , .

en URL readfile , PHP urlwrapper.

0

All Articles