-
Notifications
You must be signed in to change notification settings - Fork 17
/
music.js
38 lines (36 loc) · 850 Bytes
/
music.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
let fs = require("fs");
let axios = require("axios");
let media = [];
let ipfsArray = [];
let promises = [];
for (let i = 0; i < media.length; i++) {
promises.push(
new Promise((res, rej) => {
fs.readFile(`${__dirname}/export/${media[i]}`, (err, data) => {
if (err) rej();
ipfsArray.push({
path: `media/${i}`,
content: data.toString("base64"),
});
res();
});
})
);
}
Promise.all(promises).then(() => {
axios
.post("https://deep-index.moralis.io/api/v2/ipfs/uploadFolder", ipfsArray, {
headers: {
"X-API-KEY":
"<Your API Key>",
"Content-Type": "application/json",
accept: "application/json",
},
})
.then((res) => {
console.log(res.data);
})
.catch((error) => {
console.log(error);
});
});