【问题标题】:fine uploader S3 with large file fails带有大文件的精细上传器 S3 失败
【发布时间】:2014-12-12 18:16:43
【问题描述】:

我正在尝试使用精细上传器 s3 上传最大 500MB 的文件。 版本是 5.0.9。 这是我使用的代码。

function getFineUploaderOptions() {

    var options = {
        debug: true,
        template: "qq-template-manual-noedit",
        autoUpload: false,
        multiple: false,
        request: {
            endpoint: UploadVars.endpoint,
            accessKey: UploadVars.accessKey
        },
        signature: {
            endpoint:   "entry_essay_handler_s3.php"
        },
        uploadSuccess: {
            endpoint:   "entry_essay_handler_s3.php?success"
        },
        // required if non-File-API browsers, such as IE9 and older, are used
        iframeSupport: {
            localBlankPagePath: 'blank.html'
        },
        validation: {
            allowedExtensions: UploadVars.allowedExtensions,
            sizeLimit: UploadVars.sizeLimit
        },
        showMessage: function(message) {
            // Using Twitter Bootstrap's classes and jQuery selector and method
            console.log(message);
            $('#imageUploadmsg').html(message);
            $('#imageUploadmsg').css('visibility','visible');
        },
        objectProperties: {
            key: function (id) {
                return getUploadPath(id);
            }
        },
        chunking: {
            enabled: true

        },
        retry: {
            enableAuto: true
        },
        resume: {
            enabled: true
        },
        messages:{
            unsupportedBrowser: "You need to update your browser in order to upload a file."
        }
    };

    return options;
}

这是 uploadVars 变量。

 var UploadVars = {

  accessKey: 'somevalue',
  endpoint: "http://s3.amazonaws.com/somevalue",
  allowedExtensions: ['zip', 'rar'],
  izeLimit: '524288000',

};

在上传按钮上我使用了这段代码。

$('#imageUpload').fineUploaderS3(getFineUploaderOptions())

    .on('upload', function(event, id, name) {

    })
    .on('submit', function(event, id, name) {

    })
    .on('complete', function(event, id, name, json, xhr) {


    })
    .on('cancel', function(event, id, name, json, xhr) {

    })
    .on('autoRetry', function (event, id, name, attemptNumber) {
        // leave the code for auto Retry
    })
    .on('error', function(event, id, name, errorReason, xhr) {

    });

我总是遇到这些错误。 [Fine Uploader 5.0.9] 尝试解析签名响应时出错: SyntaxError:意外的令牌

custom.fineuploader-5.0.9.js:212 [Fine Uploader 5.0.9] 收到来自服务器的空响应或无效响应!

我确认它可以很好地处理小文件。

这是 S3 CORS 设置。

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <ExposeHeader>ETag</ExposeHeader>
        <AllowedHeader>content-type</AllowedHeader>
        <AllowedHeader>origin</AllowedHeader>
        <AllowedHeader>x-amz-acl</AllowedHeader>
        <AllowedHeader>x-amz-meta-qqfilename</AllowedHeader>
        <AllowedHeader>x-amz-date</AllowedHeader>
        <AllowedHeader>authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

而且我还更新了php.ini文件upload_max_filesize = 500MB, post_max_size = 600M 并且 phpinfo 确认我指定了正确的尺寸。

这是php端的签名过程。

function signRequest() {
    header('Content-Type: application/json');

    $responseBody = file_get_contents('php://input');
    $contentAsObject = json_decode($responseBody, true);
    $jsonContent = json_encode($contentAsObject);

    $headersStr = null;
    if (isset($contentAsObject["headers"]))
        $headersStr = $contentAsObject["headers"];


    if ($headersStr) {
        return signRestRequest($headersStr);
    }
    else {

        return signPolicy($jsonContent);

    }
}

function signRestRequest($headersStr) {
    if (isValidRestRequest($headersStr)) {
        $response = array('signature' => sign($headersStr));
    }
    else {

        logMessage("Signin is failed. Your file could not be uploaded at this time. please try again later");

        echo json_encode(array("invalid" => true, "success" => false));
        return false;
    }
    return true;
}

function isValidRestRequest($headersStr) {
    global $expectedBucketName;

    $pattern = "/\/$expectedBucketName\/.+$/";
    preg_match($pattern, $headersStr, $matches);

    return count($matches) > 0;
}

function signPolicy($policyStr) {
    $policyObj = json_decode($policyStr, true);


    if (isPolicyValid($policyObj)) {

        $encodedPolicy = base64_encode($policyStr);
        $response = array('policy' => $encodedPolicy, 'signature' => sign($encodedPolicy));
        echo json_encode($response);
    }
    else {

        logMessage("Your file could not be uploaded at this time. please try again later");

        echo json_encode(array("invalid" => true, "success" => false));
        return false;
    }
    return true;
}

function isPolicyValid($policy) {
    global $expectedMaxSize, $expectedBucketName;

    $conditions = $policy["conditions"];

    $bucket = null;
    $parsedMaxSize = null;

    for ($i = 0; $i < count($conditions); ++$i) {
        $condition = $conditions[$i];

        if (isset($condition["bucket"])) {
            $bucket = $condition["bucket"];
        }
        else if (isset($condition[0]) && $condition[0] == "content-length-range") {
            $parsedMaxSize = $condition[2];
        }
    }

    return $bucket == $expectedBucketName && $parsedMaxSize == (string)$expectedMaxSize;
}

function sign($stringToSign) {
    global $clientPrivateKey;

    return base64_encode(hash_hmac(
        'sha1',
        $stringToSign,
        $clientPrivateKey,
        true
    ));
}

谁能帮我解决这个问题? 谢谢

【问题讨论】:

  • 很明显,您从服务器返回的签名有问题。请根据代理或 Chrome 中的网络标签粘贴签名响应的全部内容(例如)。
  • 嗨。射线。我又更新了帖子。我按照fineuploader.com 的正常登录步骤进行操作。如果你愿意,我们可以亲自见面。
  • 请根据代理或Chrome中的网络标签粘贴签名响应的全部内容(例如)。
  • 您可以访问此链接88.80.131.138:8888/InSite_dev/wwwroot/1620/thankyou.php 并在电子邮件中使用georgi.kovachev2014@gmail.com,您将看到该页面。我知道为这种事情获取调试信息真的很困难。所以你可以直接看一下。

标签: fine-uploader


【解决方案1】:

您的签名服务器正在返回对 Fine Uploader 签名请求的无效响应。 Fine Uploader 需要有效的 JSON 响应,但您的服务器返回 HTML 后跟 JSON 字符串。例如,在签名 JSON 字符串之前,您的服务器将其包含在签名响应中:

<br />
<b>Deprecated</b>:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in <b>/Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/common/config/config.php</b> on line <b>18</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/common/config/config.php:18) in <b>/Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/cookiehandler.php</b> on line <b>16</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/common/config/config.php:18) in <b>/Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/cookiehandler.php</b> on line <b>32</b><br />
<br />
<b>Warning</b>:  session_start(): Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/common/config/config.php:18) in <b>/Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/entry_essay_handler_s3.php</b> on line <b>20</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/common/config/config.php:18) in <b>/Applications/MAMP/htdocs/InSite_dev/wwwroot/1620/entry_essay_handler_s3.php</b> on line <b>370</b><br />

【讨论】:

  • 感谢您的提示。但是我启用了error_display进行调试,我现在把它关掉了。你现在可以看看吗?如果您需要其他任何东西,我相信我会提供更多。
  • 现在您的签名服务器返回一个空响应 - 没有正文。你需要修复你的服务器。
  • 我已经从fineloader.com 购买了许可证。它在处理小文件时效果很好,大约 5-6MB,如果是我的服务器的问题,为什么只有大文件不起作用?你认为我们可以进行实时聊天吗?
  • 听起来您的服务器没有正确处理分块上传请求。默认情况下,较大的文件会被分块。签署这些的过程有点不同。这一切都在docs.fineuploader.com/branch/master/endpoint_handlers/… 的文档中进行了解释。
  • 谢谢,我会仔细看看
猜你喜欢
  • 2013-11-28
  • 2014-06-13
  • 1970-01-01
  • 1970-01-01
  • 2019-10-29
  • 1970-01-01
  • 2012-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多