Skip to content

Instantly share code, notes, and snippets.

@classmember
Last active February 23, 2023 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save classmember/71471d51b200ceae75d507df39e0a465 to your computer and use it in GitHub Desktop.
Save classmember/71471d51b200ceae75d507df39e0a465 to your computer and use it in GitHub Desktop.
OpenAI_server.js
// 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