-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wmg write upload #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"private": true, | ||
"scripts": { | ||
"build": "next build", | ||
"dev": "next dev", | ||
"dev": "NODE_OPTIONS='--inspect' next dev", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice for chrome devtools inspection |
||
"format": "prettier --write '**/*.{js,json,md,mdx,ts,tsx,scss,yaml,yml}'", | ||
"format-check": "prettier --check '**/*.{js,json,md,mdx,ts,tsx,scss,yaml,yml}'", | ||
"lint": "next lint --dir src --dir stories --dir .storybook --dir tests --dir scripts --dir app --dir lib --dir types", | ||
|
@@ -22,6 +22,7 @@ | |
"@storybook/addon-links": "^6.0.0", | ||
"@trussworks/react-uswds": "^5.0.0", | ||
"@uswds/uswds": "3.1.0", | ||
"formidable": "^3.5.1", | ||
"i18next": "^22.4.12", | ||
"next": "^12.1.2", | ||
"next-i18next": "^13.2.2", | ||
|
@@ -38,6 +39,7 @@ | |
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^12.1.5", | ||
"@trivago/prettier-plugin-sort-imports": "^4.1.1", | ||
"@types/formidable": "^3.4.5", | ||
"@types/jest-axe": "^3.5.5", | ||
"@types/node": "^18.15.3", | ||
"@types/react": "^17.0.2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
import formidable from "formidable"; | ||
import fs from "fs"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import os from "os"; | ||
import path from "path"; | ||
|
||
export const config = { | ||
api: { | ||
bodyParser: { | ||
sizeLimit: "10mb", | ||
}, | ||
bodyParser: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. turn off bodyParser to allow Formidable to do its thing |
||
}, | ||
}; | ||
|
||
type ResponseData = { | ||
message: string; | ||
}; | ||
|
||
export default function handler( | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<ResponseData> | ||
) { | ||
if (req.method === "POST") { | ||
const form = formidable({}); | ||
const [, files] = await form.parse(req); | ||
|
||
Object.values(files).forEach((filelist = []) => { | ||
const [file] = filelist; | ||
if (file) { | ||
const saveTo = path.join(os.tmpdir(), file.originalFilename || ""); | ||
fs.writeFileSync(saveTo, fs.readFileSync(file.filepath)); | ||
console.log(saveTo); | ||
} | ||
}); | ||
|
||
// todo: handle failure scenario! | ||
res.status(200).json({ message: "Success!" }); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this was useful for us so removed it but could add it back later... it's currently broken