3

I am trying to get an object from my AWS S3 bucket with the getObject function however, it seems like it returns a Uint8Array - which is an array of 8-bit unsigned integers. I can't figure out how to convert this back into my object I stored in my S3 bucket.

Does anybody know how to do this?
Thanks.

EDIT:

The object looks something like this:

awsServices.getObject(core.splitUrlOff(key)).then(object => ({
    key: object.key,
    description: object.description,
    likes: object.likes,
    location: object.location,
    time: object.time,
    uuids: object.uuids,
    views: object.views
}))
Jghorton14
  • 724
  • 1
  • 8
  • 25
MatTaNg
  • 923
  • 8
  • 23
  • 41
  • What is this *object* stored ? – Kaiido Apr 19 '17 at 02:43
  • I have updated my answer – MatTaNg Apr 19 '17 at 04:30
  • I might be totally off here, and sorry if that is the case, but isn't s3 storing files? And shouldn't you be using another solution to store data like this? like amazon simple DB – Millenjo Apr 19 '17 at 05:56
  • I have had success getting objects from my bucket before but with the listObjectsV2 function. I've also used getObject to get a .txt file from my bucket but I haven't used getObject yet to retrieve actual objects yet. – MatTaNg Apr 20 '17 at 01:16

1 Answers1

4

This takes an Unit8Array object, converts it to a string then converts that string to an object.

I figured it out. With tomfa's code found here: BinArraytoJson I simply did:

var binArrayToJson = function(binArray) {
    var str = "";
    for (var i = 0; i < binArray.length; i++) {
        str += String.fromCharCode(parseInt(binArray[i]));
    } 
    return JSON.parse(str)
}

Then: JSON.parse(binArrayToJson(yourBinArray));

This is from my answer: https://stackoverflow.com/a/51659985/7223300

Jghorton14
  • 724
  • 1
  • 8
  • 25