I send request to IPFS through HTTP Client:
var cleanScript = {
'type': 'script'
};
var formData = new FormData();
var jsonse = JSON.stringify(cleanScript);
var blob = new Blob([jsonse], {type: "application/json"});
formData.append('file', blob, 'file.json')
fetch('https://ipfs.infura.io:5001/api/v0/add', {
method: 'POST',
body: formData
})
.then(r => r.json())
.then(data => console.log(data))
And I can get access to this stuff through the browser, for example:
https://ipfs.infura.io/ipfs/QmZp5tQwLkMxpYHHK4a1989xYCjfUG81Po7LoaUwmxpDqP https://gateway.ipfs.io/ipfs/QmZp5tQwLkMxpYHHK4a1989xYCjfUG81Po7LoaUwmxpDqP
A link is formed by the following principle:
- protocol - http / https
- domain - ipfs.infura.io / gateway.ipfs.io / localhost:5555
- path - ipfs / ipns
- hash - hash from Response
{protocol}://{domain}/{path}/{hash}
But if I work with DAG:
var cleanScript = {
"a": 1,
"b": [1, 2, 3],
"c": {
"ca": [5, 6, 7],
"cb": "foo"
}
};
var formData = new FormData();
var jsonse = JSON.stringify(cleanScript);
var blob = new Blob([jsonse], {
type: "application/json"
});
formData.append('file', blob, 'somefile.json')
fetch('https://ipfs.infura.io:5001/api/v0/dag/put', {
method: 'POST',
body: formData
})
.then(r => r.json())
.then(data => console.log(data))
I don’t understand how the link is formed.
Can I access content through a browser?