-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransport.js
43 lines (33 loc) · 954 Bytes
/
transport.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
const http = require('http');
const fs = require('fs');
const imageFilePath = process.argv[2]; // Replace with the path of the image you want to send
fs.readFile(imageFilePath, (err, data) => {
if (err) {
console.error('Error reading the image:', err);
return;
}
const options = {
method: 'POST',
host: 'localhost',
port: 4070,
path: '/image',
headers: {
'Content-Type': 'image/png', // Replace with the appropriate content type for your image
'Content-Length': data.length,
},
};
const req = http.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
//console.log('Server response:', responseData);
});
});
req.on('error', (err) => {
console.error('Error sending the request:', err);
});
req.write(data); // Send the image data
req.end(); // End the request
});