-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat_image_ipfs_lib.html
More file actions
32 lines (31 loc) · 1.29 KB
/
cat_image_ipfs_lib.html
File metadata and controls
32 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<html>
<head>
<script src="https://unpkg.com/ipfs/dist/index.min.js"></script>
</head>
<body>
<h1>IPFS image from in browser IPFS</h1>
<pre id="log" style="width:100%;height:100px"></pre>
<img id="myimage"></img>
<script type="text/javascript">
function log(logstr) {
document.getElementById("log").innerHTML +=logstr+"\n";
}
async function f() {
var ui8arr=[]
const hash="QmcT9k932Hq4WN7K2TBAmHRhnLDVVfh7uCxQHZWJ3dZaDt";
log(`Connecting to IPFS`);
const ipfs = await window.Ipfs.create();
log(`Status = ${ ipfs.isOnline() ? 'online' : 'offline' }`);
const version = await ipfs.version().catch(x=>log(`Error: ${x}`))
log(`IPFS Version ${JSON.stringify(version)}`)
log(`Checking hash ${hash} via IPFS via browser IPFS`)
for await (const result of ipfs.cat(hash))
ui8arr.push(result) // get all parts of the image
var blob = new Blob( ui8arr ,{ type: "image/jpeg" }); // convert to blob
var url=URL.createObjectURL(blob) // make usable in img
document.getElementById("myimage").src=url;
}
f();
</script>
</body>
</html>