HTTP Server
Professional File Uploads
Production-grade configuration for XyPriss's native XHSC-powered file upload system.
Strategic Configuration
For robustness, avoid relative paths in production. Define absolute storage outside the application source.
typescript
const server = createServer({
fileUpload: {
enabled: true,
maxFileSize: 1024 * 1024 * 500, // 500MB
destination: "/var/lib/xypriss/uploads",
allowedExtensions: [".pdf", ".docx", ".zip", ".jpg", ".png"],
useSubDir: true, // Prevents directory clutter
},
});Perimeter Security
- Magic Number Validation: Verifies file headers to ensure types match extensions.
- Early Termination: Drops connection immediately if limits are exceeded.
Best Practices
- •Auth First: Always place authorization middleware before the upload handler.
- •Cleanup: Implement a cron job to delete aborted/orphaned temporary files.
Multi-Field Management
Use .fields() for transactional requests containing different types of assets.
typescript
const jobApplicationUpload = app.upload.fields([
{ name: "cv", maxCount: 1, allowedExtensions: [".pdf"] },
{ name: "photo", maxCount: 1, allowedExtensions: [".jpg", ".png"] },
]);
app.post("/apply", jobApplicationUpload, (req, res) => {
const { cv, photo } = (req as any).files;
res.success({ message: "Application received" });
});Error Handling
XyPriss throws a
FileUploadError when validation fails, allowing you to provide clean feedback to the client without exposing system internals.Response Control
Learn how to hijack and customize default 404 behaviors.
