0

我正在尝试使用edgee:slingshot上传文件,但我有几个错误。我已经按照 github 页面中的描述做了所有事情。这是我在服务器上的设置:

Slingshot.GoogleCloud.directiveDefault.GoogleSecretKey = Assets.getText('google-cloud-service-key.pem');

Slingshot.createDirective("myFileUploads", Slingshot.GoogleCloud, {
    bucket: 'dossum-app',
    GoogleAccessId: "GOOGXXXX",
    GoogleSecretKey: "qZEsLZ/NiXXXXXXXXXXXXUW8NVjSvRb8SgdxXXXXX2",
    acl: 'bucket-owner-full-control',
    authorize: function() {
        if (!this.userId) {
            var message = 'Please login before posting file';
            throw new Meteor.Error('Login Required', message);
        }

        return true;
    },
    key: function(file) {
        var user = Meteor.users.findOne(this.userId);
        return user.username + '/' + file.name;
    }
});

这是cors.json:

[{"origin": ["http://localhost:3000", "http://qnekt.zehinz.com"], "responseHeader": ["Origin", "Accept", "X-Requested-With", "Authorization", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token"], "method": ["GET", "HEAD", "DELETE", "PUT", "POST", "HEAD"], "maxAgeSeconds": 3600}]

如果我使用上述配置运行,我会收到此错误,但没有任何详细信息:{error: 500, reason: "Internal server error".... 我尝试评论此行: //GoogleSecretKey:"qZEsLZ/NiEkXo641XHIUW8NVjSvRb8SgdxIyYcV2" 这次我收到此错误:

{error: "Forbidden - 403", reason: "Failed to upload file to cloud storage", details: undefined ...

谁能指导我?

  1. 如果我使用.pem文件而不是GoogleSecretKey ,我应该在哪里获得GoogleAccessId

  2. 用于文件上传和公共阅读的 cors.json 文件应该是什么?

4

1 回答 1

5

我在使用edgee:slingshot和 Google Cloud Storage 时遇到了麻烦。但是这个设置现在对我有用:

//server
Slingshot.GoogleCloud.directiveDefault.GoogleSecretKey = Assets.getText('google-cloud-service-key.pem');

Slingshot.createDirective('avatarUploader', Slingshot.GoogleCloud, {
    bucket: 'my_bucket',
    GoogleAccessId: 'xxxxxxxxxxxxxx@developer.gserviceaccount.com',
    acl: 'public-read',
    authorize: function() {
        if (!this.userId) {
            var message = 'Please login before posting file';
            throw new Meteor.Error('Login Required', message);
        }

        return true;
    },
    key: function(file) {
        var user = Meteor.users.findOne(this.userId);
        var ext = file.type.split('/')[1];
        return user.username + '/' + randomString(20) + '.' + ext;
    }
});

//CORS settings
[
  {
    "origin": ["*"],
    "responseHeader": ["*"],
    "method": ["GET", "POST", "PUT", "HEAD"],
    "maxAgeSeconds": 3000
  }
]

详情请看这里

于 2015-05-27T03:28:37.813 回答