-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamFileRequest.js
More file actions
32 lines (28 loc) · 987 Bytes
/
streamFileRequest.js
File metadata and controls
32 lines (28 loc) · 987 Bytes
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
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');
function streamFileRequest(filePath, formUrl, token) {
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 filePath = process.argv[2];
const formUrl = process.argv[3];
const token = process.argv[4];
streamFileRequest(filePath, formUrl, token);