将缓冲区对象发回给Axios会导致错误

我创build了一个lambda函数在S3中添加的每个对象上执行。 我需要将每个文件转发到另一台服务器。

从S3中检索到的对象types是:

{ AcceptRanges: 'bytes', LastModified: 2017-05-29T18:29:47.000Z, ContentLength: 22502, ETag: '"9eff66fa38994b09e8f2072a79044734"', ContentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', Metadata: {}, Body: <Buffer 50 4b 03 04 14 00 06 00 08 00 00 00 21 00 71 d0 15 40 bc 01 00 00 de 09 00 00 13 00 08 02 5b 43 6f 6e 74 65 6e 74 5f 54 79 70 65 73 5d 2e 78 6d 6c 20 ... > } 

我拿缓冲体,然后把它放在FormData中,然后用Axios。

不过,我得到这个错误:

 Error: write after end at ClientRequest.OutgoingMessage.write (_http_outgoing.js:441:15) at Writable.RedirectableRequest._write (/var/task/node_modules/follow-redirects/index.js:186:23) at doWrite (_stream_writable.js:334:12) at clearBuffer (_stream_writable.js:441:7) at onwrite (_stream_writable.js:373:7) at WritableState.onwrite (_stream_writable.js:90:5) at CorkedRequest.finish (_stream_writable.js:548:7) at afterWrite (_stream_writable.js:388:3) at onwrite (_stream_writable.js:379:7) at WritableState.onwrite (_stream_writable.js:90:5) 

我的lambda:

 'use strict'; console.log('Loading function'); const aws = require('aws-sdk'); const axios = require('axios'); const FormData = require('form-data'); const fs = require('fs'); const async = require('async'); const s3 = new aws.S3({apiVersion: '2006-03-01'}); exports.handler = (event, context, callback) => { //console.log('Received event:', JSON.stringify(event, null, 2)); // Get the object from the event and show its content type const bucket = event.Records[0].s3.bucket.name; const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' ')); const params = { Bucket: bucket, Key: key, }; async.waterfall([ function download(next) { console.time("downloadImage"); console.log("download"); // Download the image from S3 into a buffer. // sadly it downloads the image several times, but we couldn't place it outside // the variable was not recognized s3.getObject(params, next); console.timeEnd("downloadImage"); }, function convert(response, next) { console.time("convert file to PDF"); console.log("Reponse content type : " + response.ContentType); console.log("Conversion..."); var options = { "formats": ["pdf"], "thumbnails": { "size": "320x240", } } var form = new FormData(); form.append('file', response.Body); console.log(response) axios.put('<MY SERVER URL>', form) .then(function (res) { console.log("Conversion success") next(null, res) }) .catch(function (err) { next(err); }); } ], function (err, result) { if (err) { console.error(err); } // result now equals 'done' console.log("End of step : " + result); callback(); }); }