簡體   English   中英

訪問被拒絕到S3中的存儲桶-禁止錯誤403(精細上傳程序)

[英]Access denied to bucket in S3 - Error 403 Forbidden (Fine-Uploader)

我無法訪問Amazon S3中的存儲桶。 我按照官方博客中的Fineuploader(Fineuploader S3從您的瀏覽器直接上傳到Amazon S3)中的說明進行逐步操作,我檢查了類似的問題,但沒有一個參考此特定案例。

我的意圖是復制S3的fineuploader.com演示,唯一的不同是我沒有使用高級功能(分塊,拖放,重試等),換句話說,進行了“簡單上載”。

打擾一下,如果我很冗長或很露骨,我只想弄清楚我完成的程序。

我將代碼復制到了http://fineuploader.com/demos.html#amazon-demo的客戶端,並更改了以下幾行:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="favicon.ico" >

    <title></title>

    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

</head>
<body>

<!-- jQuery ====================================================================== -->
<script src="http://code.jquery.com/jquery-latest.js"></script>

<!-- Fine Uploader JS ====================================================================== -->
<script src="../../custom.fineuploader-5.0.8.js"></script>
<script>
$(document).ready(function () {
    $('#fineuploader-s3').fineUploaderS3({
        debug: true,
        request: {
            // REQUIRED: We are using a custom domain
            // for our S3 bucket, in this case.  You can
            // use any valid URL that points to your bucket.
            endpoint: "bucketname.s3.amazonaws.com",

            // REQUIRED: The AWS public key for the client-side user
            // we provisioned.

            // Access key - User create in IAM
            accessKey: "AKIAJUGFU2PN7PXXXXXX"
        },

        template: "simple-previews-template",

        // REQUIRED: Path to our local server where requests
        // can be signed.
        signature: {
            endpoint: "/fineuploader/html/templates/s3demo.php"
        },

        // OPTIONAL: An endopint for Fine Uploader to POST to
        // after the file has been successfully uploaded.
        // Server-side, we can declare this upload a failure
        // if something is wrong with the file.
        uploadSuccess: {
            endpoint: "/fineuploader/html/templates/s3demo.php?success"
        },

        // USUALLY REQUIRED: Blank file on the same domain
        // as this page, for IE9 and older support.
        // iframeSupport: {
        //     localBlankPagePath: "/server/success.html"
        // },

        // optional feature
        // chunking: {
        //     enabled: true
        // },

        // optional feature
        // resume: {
        //     enabled: true
        // },

        // optional feature
        // deleteFile: {
        //     enabled: true,
        //     method: "POST",
        //     endpoint: "/s3demo.php"
        // },

        // optional feature
        // validation: {
        //     itemLimit: 5,
        //     sizeLimit: 15000000
        // },

        // thumbnails: {
        //     placeholders: {
        //         notAvailablePath: "images/not_available-generic.png",
        //         waitingPath: "images/waiting-generic.png"
        //     }
        // }
    })
        // Enable the "view" link in the UI that allows the file to be downloaded/viewed
        .on('complete', function(event, id, name, response) {
            var $fileEl = $(this).fineUploaderS3("getItemByFileId", id),
                $viewBtn = $fileEl.find(".view-btn");

            if (response.success) {
                $viewBtn.show();
                $viewBtn.attr("href", response.tempLink);
            }
        });
    });
</script>

<!-- Fine Uploader CSS ====================================================================== -->
<link href="../../custom.fineuploader-5.0.8.css" rel="stylesheet">

<!-- Fine Uploader DOM Element ====================================================================== -->
<div id="fineuploader-s3"></div>

<!-- Fine Uploader template ====================================================================== -->
<script type="text/template" id="simple-previews-template">
    <div class="qq-uploader-selector qq-uploader">
    <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
        <span>Drop files here to upload</span>
    </div>
    <div class="qq-upload-button-selector qq-upload-button">
        <div>Upload a file</div>
    </div>
      <span class="qq-drop-processing-selector qq-drop-processing">
          <span>Processing dropped files...</span>
          <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
      </span>
    <ul class="qq-upload-list-selector qq-upload-list">
        <li>
            <div class="qq-progress-bar-container-selector">
                <div class="qq-progress-bar-selector qq-progress-bar"></div>
            </div>
            <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
            <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
            <span class="qq-edit-filename-icon-selector qq-edit-filename-icon"></span>
            <span class="qq-upload-file-selector qq-upload-file"></span>
            <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
            <span class="qq-upload-size-selector qq-upload-size"></span>
            <a class="qq-upload-cancel-selector btn-small btn-warning" href="#">Cancel</a>
            <a class="qq-upload-retry-selector btn-small btn-info" href="#">Retry</a>
            <a class="qq-upload-delete-selector btn-small btn-warning" href="#">Delete</a>
            <a class="qq-upload-pause-selector btn-small btn-info" href="#">Pause</a>
            <a class="qq-upload-continue-selector btn-small btn-info" href="#">Continue</a>
            <span class="qq-upload-status-text-selector qq-upload-status-text"></span>
            <a class="view-btn btn-small btn-info hide" target="_blank">View</a>
        </li>
    </ul>
</div>
</script>

</body>
</html>

我在服務器端的代碼來自https://github.com/FineUploader/server-examples/blob/master/php/s3/s3demo-thumbnails-cors.php,僅注釋和更改了以下幾行。

評論行:

// require 'aws-autoloader.php';
// use Aws\S3\S3Client;

// $serverPublicKey = $_SERVER['PARAM1'];
// $serverPrivateKey = $_SERVER['PARAM2'];

// $expectedMaxSize = 15000000;

更改的行:

// Secret key - User create in IAM
$clientPrivateKey = $_SERVER['BIsYDPrOfWyWeUXueJaiaAem7he3R5THxx000Xxx'];
$expectedBucketName = "bucketname";

一切似乎都井井有條,但是當我上傳圖片時,我的Chrome控制台出現錯誤:

POST http://bucketname.s3.amazonaws.com/ 403 (Forbidden)

訪問密鑰和秘密密鑰包含為說明目的而放置的字符X和0。 密鑰不是真實的。

感謝您的幫助。

$clientPrivateKey = $_SERVER['xxx'];

我認為這是錯誤的。 在原始文件中說:

// These assume you have the associated AWS keys stored in
// the associated system environment variables
$clientPrivateKey = $_SERVER['AWS_SECRET_KEY'];

因此,要么在您的環境中設置一個名為AWS_SECRET_KEY的變量,然后將該行恢復為原來的狀態,要么只使用

$clientPrivateKey = 'xxx';

我還建議您更改密鑰,因為您現在已將其發布在公共場所,並且有人一定會在您的存儲桶中做討厭的事情!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM