Express 表示不赞成

Express 表示不赞成,express,terminal,localhost,deprecated,Express,Terminal,Localhost,Deprecated,我有一个照片应用程序,可以将照片上传到AWS。在本地主机上测试上载照片功能时,我的终端抛出以下错误: express deprecated res.send(状态,正文):使用 res.status(status).send(body)代替aws/aws.js:50:18 我的照片确实保存到AWS,我只是想知道这个错误是什么以及如何修复它。下面是错误引用的aws代码 'use strict'; var AWS = require('aws-sdk'), crypto = require

我有一个照片应用程序,可以将照片上传到AWS。在本地主机上测试上载照片功能时,我的终端抛出以下错误:

express deprecated res.send(状态,正文):使用 res.status(status).send(body)代替aws/aws.js:50:18

我的照片确实保存到AWS,我只是想知道这个错误是什么以及如何修复它。下面是错误引用的aws代码

'use strict';

var AWS = require('aws-sdk'),
    crypto = require('crypto'),
    config = require('./aws.json'),
    createS3Policy,
    getExpiryTime;

getExpiryTime = function () {
  var _date = new Date();
  return '' + (_date.getFullYear()) + '-' + (_date.getMonth() + 1) + '-' +
    (_date.getDate() + 1) + 'T' + (_date.getHours() + 3) + ':' + '00:00.000Z';
};

createS3Policy = function(contentType, callback) {
  var date = new Date();
  var s3Policy = {
    'expiration': getExpiryTime(),
    'conditions': [
      ['starts-with', '$key', 'images/'],
      {'bucket': config.bucket},
      {'acl': 'public-read'},
      ['starts-with', '$Content-Type', contentType],
      {'success_action_status' : '201'}
    ]
  };

  // stringify and encode the policy
  var stringPolicy = JSON.stringify(s3Policy);
  var base64Policy = new Buffer(stringPolicy, 'utf-8').toString('base64');

  // sign the base64 encoded policy
  var signature = crypto.createHmac('sha1', config.secretAccessKey)
  .update(new Buffer(base64Policy, 'utf-8')).digest('base64');

  // build the results object
  var s3Credentials = {
    s3Policy: base64Policy,
    s3Signature: signature,
    AWSAccessKeyId: config.accessKeyId
  };

  // send it back
  callback(s3Credentials);
};

exports.getS3Policy = function(req, res) {
  createS3Policy(req.query.mimeType, function (creds, err) {
    if (!err) {
      return res.send(200, creds);
    } else {
      return res.send(500, err);
    }
  });
};
res.send(状态码,“某物”)
替换为
res.status(状态码)。send(“某物”)

对于您的代码,这应该可以做到:

exports.getS3Policy=函数(请求、恢复){
createS3Policy(req.query.mimeType,函数(creds,err){
如果(!err){
return res.send(creds);//此处不需要200,express将默认为该值
}否则{
返回res.status(500)。发送(err);
}
});
};