Performance: Cloud storage integration concept
This concept affects page load speed and interaction responsiveness by how files are uploaded, downloaded, and served from cloud storage.
Jump into concepts and practice - no test required
app.get('/file/:id', async (req, res) => { const url = await cloudStorage.getSignedUrl(req.params.id); res.redirect(url); });
const path = require('path'); const fs = require('fs'); app.get('/file/:id', (req, res) => { const filePath = path.join(__dirname, 'uploads', req.params.id); try { const data = fs.readFileSync(filePath); res.send(data); } catch (err) { return res.status(404).send('File not found'); } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Serve files locally via Express fs.readFileSync | Minimal DOM impact | 0 reflows | High paint delay due to slow response | [X] Bad |
| Redirect to cloud storage signed URL | Minimal DOM impact | 0 reflows | Fast paint due to CDN delivery | [OK] Good |
const upload = multer({ dest: 'uploads/' });
app.post('/upload', upload.single('file'), async (req, res) => {
const params = { Bucket: 'mybucket', Key: req.file.filename, Body: fs.createReadStream(req.file.path) };
await s3.upload(params).promise();
res.send('Upload successful');
});app.post('/upload', upload.single('file'), (req, res) => {
const bucket = storage.bucket('mybucket');
bucket.upload(req.file.path, (err, file) => {
if (err) res.status(500).send('Upload error');
});
res.send('File uploaded');
});const upload = multer({ dest: 'uploads/' });
app.post('/upload-multiple', upload.array('files'), async (req, res) => {
const urls = [];
for (const file of req.files) {
const blobClient = containerClient.getBlockBlobClient(file.filename);
await blobClient.uploadFile(file.path);
urls.push(blobClient.url);
}
res.json({ uploadedUrls: urls });
});