cURL
curl --request GET \ --url https://api.example.com/api/image/:id
Authorization: Bearer <your-token>
image/jpeg
image/png
<img>
curl -X GET https://api.example.com/api/image/42 \ -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." \ --output cat-image.jpg
<img src="https://api.example.com/api/image/42" alt="Cat image" />
fetch('https://api.example.com/api/image/42', { headers: { 'Authorization': `Bearer ${token}` } }) .then(response => response.blob()) .then(blob => { const imageUrl = URL.createObjectURL(blob); document.querySelector('img').src = imageUrl; });
id
getImage(id)
images/
sendFile()
app.get('/api/image/:id', checkJwt, async (req, res) => { const id = Number(req.params.id); const fileInfo = await getImage(id); res.sendFile(path.join(imagesDir, fileInfo.name)); });