部署后,应用程序无法将文件上传到S3,会产生意外的令牌<错误

时间:2016-03-04 13:47:06

标签: meteor meteor-slingshot

我尝试将文件上传到我的S3存储区托架,从Ec 2实例获取凭据(该应用程序托管在EC2中)。这是指令:

var credentials = new AWS.EC2MetadataCredentials();

var updateCredentials = Meteor.wrapAsync(credentials.get, credentials);


Slingshot.createDirective("achievementPhotoUpload", Slingshot.S3Storage.TempCredentials, {
  bucket: "...",

  acl: "public-read",

  region: "...",

  temporaryCredentials: function () {
    if (credentials.needsRefresh()) {
      updateCredentials();
    }

    return {
      AccessKeyId: credentials.accessKeyId,
      SecretAccessKey: credentials.secretAccessKey,
      SessionToken: credentials.sessionToken
    };
  },

  authorize: function () {
    //Deny uploads if user is not logged in.
    if (!this.userId) {
      var message = "Please login before posting files";
      throw new Meteor.Error("Login Required", message);
    }

    return true;
  },

  key: function (file) {
    return "achievement-photos/" + file.name;
  }
});

但它不会上传。当我查看日志时,我发现了这个:

Session terminated, terminating shell... ...terminated.
`Meteor.addCollectionExtension` is deprecated, please use `CollectionExtensions.addExtension`
Exception while invoking method 'slingshot/uploadRequest' SyntaxError: Unexpected token <
    at Object.Future.wait (/opt/kwabackend/app/programs/server/node_modules/fibers/future.js:420:15)
    at packages/meteor/helpers.js:119:1
    at Object.temporaryCredentials (server/uploaders/AchievementPhotosAccess.js:21:7)
    at Object.Slingshot.S3Storage.TempCredentials._.defaults.applySignature (packages/edgee_slingshot/packages/edgee_slingshot.js:776:$
    at Object.Slingshot.S3Storage.upload (packages/edgee_slingshot/packages/edgee_slingshot.js:696:1)
    at [object Object]._.extend.getInstructions (packages/edgee_slingshot/packages/edgee_slingshot.js:343:1)
    at [object Object].Meteor.methods.slingshot/uploadRequest (packages/edgee_slingshot/packages/edgee_slingshot.js:425:1)
    at packages/check/match.js:103:1
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
    at Object.Match._failIfArgumentsAreNotAllChecked (packages/check/match.js:102:1)
    - - - - -
    at Object.parse (native)
    at /opt/kwabackend/app/programs/server/npm/peerlibrary_aws-sdk/node_modules/aws-sdk/lib/metadata_service.js:115:38
    at IncomingMessage.<anonymous> (/opt/kwabackend/app/programs/server/npm/peerlibrary_aws-sdk/node_modules/aws-sdk/lib/metadata_serv$
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickDomainCallback (node.js:492:13)

知道发生了什么事吗?

AchievementPhotosAccess.js的第21行:

updateCredentials();

0 个答案:

没有答案