1

I am accessing the xml file from the S3 bucket using

var params = {
  Bucket: "bucketName", 
  Key: "xmlFileName.xml"
 };

 s3.getObject(params, function(err, data) 
 {
   if (!err) 
   {
       console.log(data);
   }
}

If I open up the comment in the log I get

 2017-12-21T04:23:53.991Z   bf6be172-e606-11e7-97cb-2139c6f9555f    { AcceptRanges: 'bytes',
LastModified: 2017-12-19T01:33:35.000Z,
ContentLength: 119567,
ETag: '"88764498c11c434213fb3929235a12a5"',
ContentType: 'text/xml',
Metadata: {},
Body: <Buffer 3c 42 4c 5f 50 65 72 73 6f 6e 6e 65 6c 52 65 70 6c 69 63 61 74 65 20 78 6d 6c 6e 73 3a 69 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 77 33 2e 6f 72 67 2f ... > } undefined

Im assuming the content of the body is the serialized contents of the Xml file...Now how do I store this in a variable?

Ive tried

data.body
data[0].body

both coming back as undefined.

Please advise

John
  • 3,965
  • 21
  • 77
  • 163

1 Answers1

0

Try data.Body (capital letter). It's a Buffer so you'll need to convert it to a String before parsing the XML - try:

var xmlString = data.Body.toString()
ahoang18
  • 143
  • 7