Last active
February 23, 2023 04:39
-
-
Save classmember/71471d51b200ceae75d507df39e0a465 to your computer and use it in GitHub Desktop.
OpenAI_server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prompt: | |
// Write a node backend which accepts a .zip file from the JavaScript function in the following backticks: | |
// (the code in backticks ``` was here: https://gist.github.com/classmember/72ab335223722623af9ed5346e5ed6eb ) | |
const express = require('express'); | |
const multer = require('multer'); | |
const fs = require('fs'); | |
const app = express(); | |
// Multer is a node.js middleware for handling multipart/form-data | |
const upload = multer({ | |
dest: '/uploads' | |
}); | |
// This route handles the upload of the .zip file | |
app.post('/upload', upload.single('file'), (req, res) => { | |
let file = req.file; | |
// Read the zip file | |
fs.readFile(file.path, (err, data) => { | |
if (err) { | |
return res.status(500).send({ | |
success: false, | |
message: 'Error reading file.' | |
}); | |
} | |
// Do something with the data | |
// ... | |
// Return a success response | |
return res.status(200).send({ | |
success: true, | |
message: 'Upload successful!' | |
}); | |
}); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment