s3文件上传未返回响应

Pat*_*uan 2 javascript amazon-s3 amazon-web-services node.js

我正在使用Node AWS-SDK将文件上传到现有的S3存储桶。使用下面的代码,文件最终会上传,但似乎几次都没有返回状态代码。同样,文件成功上传后,return语句也不会执行。

exports.create = function(req, res) {
	var stream = fs.createReadStream(req.file.path);
	var params = {
		Bucket: 'aws bucket',
		Key: req.file.filename,
		Body: stream,
		ContentLength: req.file.size,
		ContentType: 'audio/mp3'
	};
	var s3upload = s3.upload(params, options).promise();
	
	s3upload
		.then(function(data) {
			console.log(data);
			return res.sendStatus(201);
		})
		.catch(function(err) {
			return handleError(err);
		});
}
Run Code Online (Sandbox Code Playgroud)

日志

POST /api/v0/episode/upload - - ms - -
POST /api/v0/episode/upload - - ms - -
{ Location: 'https://krazykidsradio.s3-us-west-2.amazonaws.com/Parlez-vous%2BFrancais.mp3',
  Bucket: 'krazykidsradio',
  Key: 'Parlez-vous+Francais.mp3',
  ETag: '"f3ecd67cf9ce17a7792ba3adaee93638-11"' }
Run Code Online (Sandbox Code Playgroud)

gue*_*314 5

同样,文件成功上传后,return语句也不会执行。

没有值return从编create()通话,看到为什么undefined值在链接到承诺。那么()?

exports.create = function(req, res) {
    var stream = fs.createReadStream(req.file.path);
    var params = {
        Bucket: 'aws bucket',
        Key: req.file.filename,
        Body: stream,
        ContentLength: req.file.size,
        ContentType: 'audio/mp3'
    };
    var s3upload = s3.upload(params, options).promise();
    // return the `Promise`
    return s3upload
        .then(function(data) {
            console.log(data);
            return res.sendStatus(201);
        })
        .catch(function(err) {
            return handleError(err);
        });
}
Run Code Online (Sandbox Code Playgroud)