Skip to content

Instantly share code, notes, and snippets.

@samuelkarani
Created December 19, 2022 16:43
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 samuelkarani/ea5a4b83045f23310f688a4e854149e7 to your computer and use it in GitHub Desktop.
Save samuelkarani/ea5a4b83045f23310f688a4e854149e7 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const crypto = require("crypto");
app.post('/upload', async (req, res) => {
const randomId = crypto.randomBytes(16).toString("hex");
const filePath = __dirname + "/uploads/" + randomId;
const writeStream = fs.createWriteStream(filePath);
writeStream.on('finish', () => {
const { is_infected, viruses } = await scanFile(filePath);
if (!is_infected) {
// upload to AWS S3
}
})
request.pipe(writeStream);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment