-
Notifications
You must be signed in to change notification settings - Fork 1
/
store.js
26 lines (21 loc) · 988 Bytes
/
store.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
import { Web3Storage } from 'https://cdn.jsdelivr.net/npm/web3.storage/dist/bundle.esm.min.js'
function getAccessToken() {
//Accessing Storage Token
return 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweERFODU3RUU4M0FDOTBmQTgwRUI1ZkJCMUQ3Nzg2ODlCMGMyOGMwMDYiLCJpc3MiOiJ3ZWIzLXN0b3JhZ2UiLCJpYXQiOjE2ODA5NjMwNzE3MjcsIm5hbWUiOiJOaW1idXMgMmsyMyJ9.K5655HTdno4DTFdKRmEJ68Ooa-RQgF7HSJW63B-IvQg';
}
export function makeStorageClient() {
return new Web3Storage({ token: getAccessToken() })
}
function getFiles() {
//Accessing Input Files
const fileInput = document.querySelector('input[type="file"]')
return fileInput.files
}
document.getElementById("submit").onclick = async function storeFiles() {
const name=document.getElementById('name');
const files = getFiles();
const client = makeStorageClient()
const cid = await client.put(files,{name:name.value})
window.alert('File stored with cid: ')
document.upload.reset();
};