-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
44 lines (37 loc) · 940 Bytes
/
App.js
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
33
34
35
36
37
38
39
40
41
42
43
44
import logo from './logo.svg';
import './App.css';
import { useState } from 'react'
import { create } from 'ipfs-http-client'
const client = create('https://ipfs.infura.io:5001/api/v0')
function App() {
const [fileUrl, updateFileUrl] = useState(``)
async function onChange(e) {
const file = e.target.files[0]
try {
const added = await client.add(file)
console.log(added);
const url = `https://ipfs.infura.io/ipfs/${added.path}`
updateFileUrl(url)
} catch (error) {
console.log('Error uploading file: ', error)
}
}
return (
<div className="App">
<header className="App-header">
<h1>IPFS Example</h1>
<input
type="file"
onChange={onChange}
/>
{
fileUrl && (
<img src={fileUrl} width="600px" />
)
}
<h6>{fileUrl}</h6>
</header>
</div>
);
}
export default App;