Created
February 15, 2023 09:23
-
-
Save WoolDoughnut310/a40a0e3483a47f08354d509b32baa8dd to your computer and use it in GitHub Desktop.
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
import formidable from "./formidable-serverless"; | |
import { createReadStream } from "fs"; | |
import { IncomingMessage } from "http"; | |
import { NextApiRequest, NextApiResponse } from "next"; | |
import parseForm from "./parseForm"; | |
import * as gcs from "./gcs"; | |
import { Response } from "express"; | |
export const method1 = async ( | |
req: NextApiRequest | IncomingMessage, | |
res: NextApiResponse | Response | |
) => { | |
const form = formidable(); | |
const { files } = await parseForm(form, req); | |
const file = files.file as any; | |
createReadStream(file.path) | |
.pipe(gcs.createWriteStream(file.name, file.type)) | |
.on("finish", () => { | |
res.status(200).json("File upload complete"); | |
}) | |
.on("error", (err) => { | |
console.error(err.message); | |
res.status(500).json("File upload error: " + err.message); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment