This file contains hidden or 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
... | |
const config = { | |
headers: { 'content-type': 'multipart/form-data' }, | |
onUploadProgress: (event) => { | |
console.log(`Current progress:`, Math.round((event.loaded * 100) / event.total)); | |
}, | |
}; | |
const response = await axios.post('/api/uploads', formData, config); | |
... |
This file contains hidden or 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 nextConnect from 'next-connect'; | |
import multer from 'multer'; | |
// Returns a Multer instance that provides several methods for generating | |
// middleware that process files uploaded in multipart/form-data format. | |
const upload = multer({ | |
storage: multer.diskStorage({ | |
destination: './public/uploads', | |
filename: (req, file, cb) => cb(null, file.originalname), | |
}), |
This file contains hidden or 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 nextConnect from 'next-connect'; | |
import multer from 'multer'; | |
const upload = multer({ | |
storage: multer.diskStorage({ | |
destination: './public/uploads', | |
filename: (req, file, cb) => cb(null, file.originalname), | |
}), | |
}); |
This file contains hidden or 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
... | |
export default apiRoute; | |
export const config = { | |
api: { | |
bodyParser: false, // Disallow body parsing, consume as stream | |
}, | |
}; |
This file contains hidden or 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 nextConnect from 'next-connect'; | |
const apiRoute = nextConnect({ | |
// Handle any other HTTP method | |
onNoMatch(req, res) { | |
res.status(405).json({ error: `Method '${req.method}' Not Allowed` }); | |
}, | |
}); | |
// Process a POST request |
This file contains hidden or 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
export default (req, res) => { | |
if (req.method === 'POST') { | |
// Process a POST request | |
res.status(200).json({ data: 'success' }); | |
} else { | |
// Handle any other HTTP method | |
res.status(405).json({ error: `Method '${req.method}' Not Allowed` }); | |
} | |
}; |
This file contains hidden or 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
const AboutRoute: NextPage<IProps> = (props) => { | |
return ( | |
<> | |
<Head> | |
<AnyChartScript /> | |
</Head> | |
<Layout title="About"> | |
<AboutPage /> | |
</Layout> | |
</> |
This file contains hidden or 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
class NextDocument extends Document { | |
render() { | |
return ( | |
<Html lang="en" dir="ltr"> | |
<Head> | |
<AnyChartScript /> | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> |
This file contains hidden or 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
// AnyChartScript.tsx | |
export const AnyChartScript: React.FC<IProps> = (props) => { | |
return <script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-base.min.js" type="text/javascript" />; | |
}; |