forked from NTUEELightDance/LightDance-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitDB.js
48 lines (44 loc) · 1.29 KB
/
initDB.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
/**
* node initDB.js
*/
const axios = require("axios");
const fs = require("fs");
const FormData = require("form-data");
const filePath = process.argv[2];
const instance = axios.create({
baseURL: "http://localhost:4000/",
// baseURL: "http://localhost:8080/",
maxContentLength: Infinity,
maxBodyLength: Infinity,
});
async function main() {
// const file = fs.createReadStream(filePath);
const formData = new FormData();
formData.append("data", fs.createReadStream(filePath));
const options = {
headers: Object.assign(
{ "Content-Type": "multipart/form-data" },
formData.getHeaders()
),
};
const response = await instance
.post("/api/uploadData", formData, options)
// .post("/api/editor-server/uploadData", formData, options)
.catch(function (error) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log("Error", error.message);
}
});
if (response) {
console.log(response.status);
}
}
main();