-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuploadToIpfs.js
73 lines (61 loc) · 2.28 KB
/
uploadToIpfs.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const fs = require('fs')
const { NFTStorage, File, Blob } = require('nft.storage')
async function uploadJsonData(JsonData) {
console.log('Starting logging:', process.env.NFT_STORAGE_API_KEY)
const client = new NFTStorage({ token: process.env.NFT_STORAGE_API_KEY })
console.log('Uploding json...')
// const imageFile = new File([imageData], `${baseFileName}.${imgType}`, {
// type: `image/${imgType}`,
// })
const someData = new Blob([JsonData])
const hashCID = await client.storeBlob(someData)
// console.log('Uploding mp4...');
// const animationData = fs.readFileSync(`./assets/${baseFileName}.mp4`)
// const animationFile = new File([animationData], `${baseFileName}.mp4`, { type: ' video/mp4' });
// const animationCID = await client.storeBlob(animationFile);
return {
hashCID,
}
}
async function uploadData(baseFileName, isJPG) {
let imgType
if (isJPG) imgType = 'jpg'
else imgType = 'png'
console.log('Starting logging:', process.env.NFT_STORAGE_API_KEY)
const client = new NFTStorage({ token: process.env.NFT_STORAGE_API_KEY })
console.log('Uploding image...')
const imageData = fs.readFileSync(
`./sugar-pretzels/${baseFileName}.${imgType}`,
)
const imageFile = new File([imageData], `${baseFileName}.${imgType}`, {
type: `image/${imgType}`,
})
const imageCID = await client.storeBlob(imageFile)
// console.log('Uploding mp4...');
// const animationData = fs.readFileSync(`./assets/${baseFileName}.mp4`)
// const animationFile = new File([animationData], `${baseFileName}.mp4`, { type: ' video/mp4' });
// const animationCID = await client.storeBlob(animationFile);
return {
imageCID,
}
}
async function main() {
// const { imageCID } = await uploadData('0', false)
const { imageCID } = await uploadJsonData(
JSON.stringify({ tryial: 3, new: 'joo' }),
)
console.log('================================================')
console.log(`Image CID: ${imageCID}`)
// console.log(`Animation CID: ${animationCID}`)
console.log('Put those two hashes in the argument.js file')
console.log('================================================')
}
// main()
// .then(() => process.exit(0))
// .catch((error) => {
// console.error(error)
// process.exit(1)
// })
module.exports = {
uploadJsonData,
}