【问题标题】:evaporate.js s3 direct uploads 403evapor.js s3 直接上传 403
【发布时间】:2018-09-13 23:03:21
【问题描述】:

我正在尝试使用蒸发 js 将文件直接上传到浏览器到 S3。 我按照jqueryajaxphp.com 上的教程进行操作,但我遇到了签名问题

Signature.php

<?php

$to_sign = $_GET['to_sign'];
$secret = 'AWS_SECRET';
$hmac_sha1 = hash_hmac('sha1', $to_sign, $secret, true);
$signature = base64_encode($hmac_sha1);
echo $signature;

上传功能

function largeFileUPload(file) {

    var ins = new Evaporate({
        signerUrl: './includes/s3-signature.php',
        aws_key: "AWS_KEY_XXXXXXX",
        bucket: 'bucket-name',
        awsRegion: 'eu-west-1',
        cloudfront: true,
        aws_url: 'http://bucket-name.s3-accelerate.amazonaws.com',
        // partSize: 10 * 1024 * 1024,
        s3Acceleration: true,
        computeContentMd5: true,
        cryptoMd5Method: function (data) { return AWS.util.crypto.md5(data, 'base64'); },
        cryptoHexEncodedHash256: function (data) { return AWS.util.crypto.sha256(data, 'hex'); }
    });
    // http://<?=$my_bucket?>.s3-<?=$region?>.amazonaws.com

    ins.add({
        name: 'evaporateTest' + Math.floor(1000000000*Math.random()) + '.' + file.name.replace(/^.*\./, ''),
        file: file,
        xAmzHeadersAtInitiate : {
            'x-amz-acl': 'public-read'
        },
        signParams: {
            foo: 'bar'
        },
        complete: function(r){
            console.log('Upload complete');
        },
        progress: function(progress){
            var progress = Math.floor(progress*100);
            console.log(progress);
        },
        error: function(msg){
            console.log(msg);
        }
    });
}

我正在关注来自 s3 端点的响应

<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

我也尝试过 blueimp 插件,但文件超过 200MB 时失败

【问题讨论】:

    标签: file amazon-web-services amazon-s3 file-upload evaporate.js


    【解决方案1】:

    来自jqueryajaxphp.com 的教程中的 Signature.php 文件导致了问题。我从evapor.js文档中更改了php签名文件,它解决了问题

    Signature.php

    $to_sign = $_GET['to_sign'];
    $secret = 'AWS_SECRET';
    
    $formattedDate = substr($dateTime, 0, 8);
    
    //make the Signature, notice that we use env for saving AWS keys and regions
    $kSecret = "AWS4" . $secret;
    $kDate = hash_hmac("sha256", $formattedDate, $kSecret, true);
    $kRegion = hash_hmac("sha256", "eu-west-1", $kDate, true);
    $kService = hash_hmac("sha256", 's3', $kRegion, true);
    $kSigning = hash_hmac("sha256", "aws4_request", $kService, true);
    $signature = hash_hmac("sha256", $to_sign, $kSigning);
    
    echo $signature;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-05
      • 2014-06-24
      • 2011-05-12
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 2012-03-14
      • 2020-09-23
      相关资源
      最近更新 更多