File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ import rick from "buffer-loader!../../rick.jpg" ;
2
+
3
+ export default ( req , res ) => {
4
+ res . status ( 200 ) ;
5
+ res . setHeader ( "Content-Type" , "image/jpeg" ) ;
6
+ // Send the image buffer. There are many other ways to send images and other
7
+ // files. For example, you can create a buffer from a base64-encoded string
8
+ // of an image: https://stackoverflow.com/a/28440633/6451879
9
+ // res.send(Buffer.from(%BASE64-STRING%, "base64"))
10
+ res . send ( rick ) ;
11
+ } ;
Original file line number Diff line number Diff line change @@ -135,6 +135,17 @@ const Index = () => (
135
135
with content-type XML
136
136
</ a >
137
137
</ li >
138
+ < li >
139
+ < a href = '/api/image' >
140
+ with image response
141
+ </ a >
142
+ { ' ' }
143
+ (
144
+ < a href = 'https://github.com/FinnWoelm/next-on-netlify-demo/tree/master/pages/api/image.js' >
145
+ code
146
+ </ a >
147
+ )
148
+ </ li >
138
149
</ ul >
139
150
140
151
< h2 > Preview Mode</ h2 >
File renamed without changes.
You can’t perform that action at this time.
0 commit comments