js-ipfs adding file to a node not correctly working - ipfs

Hello please help me with this guys
The add method not adding file to directory
This is current status
c.files.mkdir("metadata")
c.add([{path:"/metadata/0.json", content:""}]).then((r)=>console.log(r))
This is returned json object
{
path: 'metadata',
cid: CID(QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn),
size: 4
}

Fixed the code with
client.files.write('/metadata/name',content,{create:true})

Related

How to generate Json file after execution finish

I'm working with cucumber and protractor and to generate reports i'm using
cucumber-html-reporter I already add the configuration to generate the report
var options = {
theme: 'bootstrap',
jsonFile: 'reporter/cucumber_report.json',
output: 'reporter/cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: true,
};
defineSupportCode(function({ After }) {
After((scenario)=> {
reporter.generate(options);
});
});
but i'm not generate the json file with this code, I search in google and the code to generate the json file should be add into the cucumberOpts in the conf.js but i'm not sure what's the code should be into cucumberOpts to generate the json file and the convert into report.
I hope you can help me guys.
Maybe this can help you, it's for Typescript but the code is almost the same. You can export the file in an After-hook. The link is for CucumberJS 1, if you look into the master branch you can also find the CucumberJS 2 solution
The advantage of this in comparison to generating the JSON file with the format option is that you can modify the JSON before saving
Hope it helps
For people that still have this problem, in my case the problem was that I was using cucumber v1 instead cucumber v2. For this case I should use registerHandler instead After this is the complete example:
defineSupportCode(function({registerHandler}) {
registerHandler('AfterFeatures', function (features) {
reporter.generate(options);
});
});
Hope this help u guys.

response with status 200: ok

I am trying to figure out how to plot data from a local '.JSON' file using angular2-highcharts example.
I followed the example in 'https://www.npmjs.com/package/angular2-highcharts' to first understand how to plot .JSON data and it worked. I took the data available for the example and created a local .JSON file (copied the content from 'https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=JSONP_CALLBACK' in notepad and saved it with UTF-8 encoding as a .JSON file), and replaced the file path for the JSON request to this. When I do this though, I get an error - response with status 200.
constructor(jsonp : Jsonp) {
//jsonp.get('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=JSONP_CALLBACK').subscribe(res => {
jsonp.get('./data.json').subscribe(res => {
this.options = {
title : { text : 'AAPL Stock Price' },
series : [{
name : 'AAPL',
data : res.json(),
tooltip: {
valueDecimals: 2
}
}]
};
});
}
options: Object;
};
Since I am not super familiar with json data/ Javascript or angular2 I am not sure if I am missing something very basic here. Any help is appreciated.
as far as I know, Response Status 200 specifies that request was successful. i.e. your request was successfully handled. perhaps you want to try checking response data.
check your callback for response data.
Using http instead of json helped. I made use of the suggestion in this answer https://stackoverflow.com/a/36305814/4567096.

Papa Parse reading CSV locally

Can someone point to or show me a working example of Papa Parse reading a csv file.
When I try to use :
Papa.parse(file, {
complete: function(results) {
console.log("Finished:", results.data);
}
});
the file name is returned in the array instead of the data within. None of the internet examples actually work. The official demo works correctl inspecting its code I cant find it making use of the above strangely.
As #Matt mentioned in his comment, the trick is not to pass a file name, but a file object. This also was not intuitive to me at first, so here is a quick solution:
var data;
function parse() {
var file = document.getElementById('myDOMElementId').files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
console.log("Finished:", results.data);
data = results.data;
}
});
}
Note that you have to call the results in this way when working with a local file. If you want to work with the results elsewhere, assign it to a global variable.
I have faced the same problem and it was solved by 2 actions:
1- Adding a callback function
2- connecting to a local oython server/changing browser's security settigns
Check this:
https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally
I did not pass an object but a string with the file name/path and it worked for me.

Grunt - read json object from file

I want to use grunt-hash plugin for renaming my js files.
This plugin create a new file containing map of renamed files:
hash: {
options: {
mapping: 'examples/assets.json', //mapping file so your server can serve the right files
Now I need to fix links to this files by replacing all usages (rename 'index.js' to 'index-{hash}.js') so I want to use grunt-text-replace plugin.
According to documentation I need to cofigure replacements:
replace: {
example: {
replacements: [{
from: 'Red', // string replacement
to: 'Blue'
}]
}
}
How could I read json mapping file to get {hash} values for each file and provide them to replace task?
grunt.file.readJSON('your-file.json')
is probably what you are looking for.
I've set up a little test. I have a simple JSON file 'mapping.json', which contains the following JSON object:
{
"mapping": [
{"file": "foo.txt"},
{"file": "bar.txt"}
]
}
In my Gruntfile.js I've written the following simple test task, which reads the first object in the 'mapping'-array:
grunt.registerTask('doStuff', 'do some stuff.', function() {
mapping = grunt.file.readJSON('mapping.json');
grunt.log.write(mapping.mapping[0]["file"]).ok();
});
When invoking the Grunt task, the console output will be as follows:
$ grunt doStuff
Running "doStuff" task
foo.txtOK
Done, without errors.
I hope this helps! :)

Get JSON data from WebAPI & Load data into Store

I am learning ExtJS-4.2, I was following their MVC tutorial...
I built my controller, view, model, store... My Store had hard-coded data. I have a working WebAPI for testing, which sends result in json format...
What the tutorial is talking about how to read from local file and send to an API,
what i want to read from API and load my data into the store...
Ext.define('AM.store.Productstore',
{
extend : 'Ext.data.Store',
model : 'AM.model.Productmodel',
autoload : true,
proxy : {
type : 'AJAX',
url : 'localhost/mfw/api/products/all'
//tutorial is no help any furthur from this point on
}
});
My URL is localhost/mfw/api/products/all
and my returning json is
[{"ID":1,"Name":"aa","Category":"A","Price":200.00},
{"ID":2,"Name":"bb","Category":"B","Price":200.00
{"ID":3,"Name":"cc","Category":"C","Price":200.00},
{"ID":4,"Name":"dd","Category":"D","Price":200.00},
{"ID":5,"Name":"ee","Category":"E","Price":200.00},
{"ID":6,"Name":"ee","Category":"F","Price":200.00}]
any help?
Please change your proxy type to 'rest' instead of 'Ajax'. More over mention your reader config. Did you map your json key with fields in model.
please refer sencha guide for more clarity.
http://docs.sencha.com/ext-js/4-2/#!/guide/data
Thanks
Here is a jsfiddle showing a grid with your data. One of the key things is the root property of the json reader. Since your data does not have a root you can leave the root property out and it should work. If you data is wrapped inside another field ie root field then specify root: 'myrootfield' in the reader. So here is your proxy. Also in your model specify the key field using idProperty in your case it is 'ID', I think extjs defaults to idProperty of 'id' lowercase so better to just specify it directly.
proxy : {
type : 'rest',
url : 'localhost/mfw/api/products/all'
reader: {
type: 'json'
}
}