How to create a tiddler from json inside javascript macro

37 views
Skip to first unread message

Justin B

unread,
Aug 22, 2018, 5:31:41 PM8/22/18
to tiddl...@googlegroups.com
Hello everyone, 

This is my first time posting so please let me know if there is additional context or conventions I should be providing. 

I am trying to retrieve a json object in the format they are imported and exported by TiddlyWiki from AWS S3 and then create a tiddler with the response. I am new to Javascript and am very open to suggestions for other improvements. 

My code which successfully retrieves the object and writes the json to the console is as follows: 

```
(function(){

"use strict";

exports.name = "getobject";
exports.params = [
{key: ""}
];

exports.run = function(key) {
  
function handleresult(err, data) {
            if(err)throw err;
            console.log(data.Body.toString('utf-8'));
// Make a tiddler out of data.Body.toString('utf-8') here
return data
}


AWS.config.update({
  accessKeyId: 'MyAccessKey', 
  secretAccessKey: 'MySecretKey', 
  region: 'us-east-2'
});
var s3 = new AWS.S3();
var params = { 
 Bucket: 'testtiddlybucket',
 Key: key
}
var result = s3.getObject(params, handleresult);

return "Results from list objects call with prefix " + result
};

})();
```
Is there a Javascript macro I can call to implement the Tiddler creation? 

Thanks in advance!
Reply all
Reply to author
Forward
0 new messages