使用Meteor Slingshot将文件上传到s3已停止使用错误403

时间:2017-02-14 15:04:06

标签: meteor amazon-s3 meteor-slingshot

我一直在使用meteor-slingshot将文件上传到亚马逊S3一段时间。突然间,我的上传功能似乎都无法正常工作。我尝试上传文件时收到以下错误。

Error uploading errorClass {error: "Forbidden - 403", reason: "Failed to upload file to cloud storage", details: undefined, message: "Failed to upload file to cloud storage [Forbidden - 403]", errorType: "Meteor.Error"…}

上周所有上传工作正常,突然之间我在所有项目中都遇到了上述错误。我不知道弹弓包装有什么问题,或者是否对s3政策做了一些改变。

这是我正在使用的代码

Slingshot.fileRestrictions("myFileUploads", {
    allowedFileTypes: ["image/png", "image/jpeg", "image/gif" ,],
    maxSize: null // 10 MB (use null for unlimited).
});


Slingshot.createDirective("myFileUploads", Slingshot.S3Storage, {
    bucket: "*****",
    acl: "public-read",
    region : "ap-southeast-1",
    AWSAccessKeyId : "MyAccessKey",
    AWSSecretAccessKey : "MySecretKey",

    authorize: function () {
       return true;
    },

    key: function (file) {
        var imageName = getUniqueID()
        return  "images/" + imageName;
    }
});

getUniqueID = function(){
    this.length = 8;
    this.timestamp = +new Date;
    var ts = this.timestamp.toString();
    var parts = ts.split( "" ).reverse();
    var id = "";
    var _getRandomInt = function( min, max ) {
        return Math.floor( Math.random() * ( max - min + 1 ) ) + min;
    }
    for( var i = 0; i < this.length; ++i ) {
        var index = _getRandomInt( 0, parts.length - 1 );
        id += parts[index];  
    }
    return id;
}

这是我的CORS配置

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

我的桶政策

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::MyBucketName/*"
        }
    ]
}

0 个答案:

没有答案