-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEdgeLens.js
More file actions
36 lines (29 loc) · 1.08 KB
/
EdgeLens.js
File metadata and controls
36 lines (29 loc) · 1.08 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
const express = require('express');
const multer = require('multer');
const axios = require('axios');
const fs = require('fs');
const upload = multer({ dest: 'uploads/' }); // Multer configuration for file uploads
const app = express();
app.use(express.static('public')); // To serve the client-side HTML and JS files
app.post('/your-server-side-endpoint', upload.single('image'), async (req, res) => {
try {
const imageFilePath = req.file.path;
const file = fs.createReadStream(imageFilePath);
const formData = new FormData();
formData.append('image', file);
const openAIResponse = await axios({
method: 'post',
url: 'https://api.openai.com/v1/images/generations',
data: formData,
headers: {
'Authorization': 'Bearer your-openai-api-key',
...formData.getHeaders(),
},
});
res.json(openAIResponse.data);
} catch (error) {
console.error('Error processing image:', error);
res.status(500).json({ error: 'Error processing image' });
}
});
app.listen(3000, () => console.log('Server listening on port 3000'));