-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTokenAndStreamFileRequest.js
More file actions
48 lines (41 loc) · 1.42 KB
/
getTokenAndStreamFileRequest.js
File metadata and controls
48 lines (41 loc) · 1.42 KB
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
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');
async function streamFileRequest(tokenUrl, username, password, filePath, formUrl) {
try {
const response = await axios.post(tokenUrl, {
username: username,
password: password
});
token = response.data.token
console.log('[Getting Token] Success: ', token);
} catch (error) {
console.error('[Getting Token] Error: ', error);
throw error;
}
try {
const formData = new FormData();
formData.append('file', fs.createReadStream(filePath));
axios.post(formUrl, formData, {
headers: {
...formData.getHeaders(),
'Content-Type': 'application/octet-stream',
'Authorization': `Bearer ${token}`
}
})
.then((response) => {
console.log('[Sending Stream Request] Success: ', response.data);
})
.catch((error) => {
console.error('[Sending Stream Request] Error: ', error);
});
} catch (error) {
console.error('[Sending Stream Request] Error: ', error);
}
}
const tokenUrl = process.argv[2];
const username = process.argv[3];
const password = process.argv[4];
const filePath = process.argv[5];
const formUrl = process.argv[6];
streamFileRequest(tokenUrl, username, password, filePath, formUrl);