File Post with Multipart Form
Overview
This NetBurner application provides a web-based file upload interface that allows users to upload files to the NetBurner device via HTTP POST requests. The uploaded files are processed and displayed back to the user in a web browser, with options for both text and binary data visualization.
Features
- Web-based file upload: Simple HTML form interface for selecting and uploading files
- Multipart form data support: Handles file uploads using the standard multipart/form-data encoding
- File processing: Reads and processes uploaded files up to 10KB in size
- Dual display modes:
- Text mode: Shows readable characters with HTML entity encoding
- Binary mode: Shows both hexadecimal and ASCII representation of file data
- Real-time feedback: Console output showing POST processing events
Architecture
Core Components
- main.cpp: Application initialization and network setup
- formcode.cpp: HTTP POST processing and file handling logic
- index.html: Main web page with file upload form
- filepost.html: Target page for form submission (handled by callback)
Key Functions
ProcessPostFile(): Reads uploaded file data into memory buffer
ShowFileData(): Displays file contents in web browser with formatting
PostCallBack(): Handles POST events and coordinates file processing
UserMain(): Initializes network stack and web server
Technical Details
Memory Management
- File buffer size: 10,000 bytes (10KB maximum file size)
- Uses static buffer allocation for file storage
- Automatic cleanup of file descriptors after processing
Security Features
- HTML entity encoding for special characters <, >, &, "
- Input validation and size limits
- Controlled file access through NetBurner's HTTP framework
Network Configuration
- Uses DHCP for automatic IP address assignment
- HTTP server runs on default port 80
- 5-second timeout for network initialization
Usage
Setup
- Deploy the application to a NetBurner device
- Connect the device to your network
- Wait for DHCP address assignment
- Note the device's IP address from console output
File Upload Process
- Open web browser and navigate to the device's IP address
- Select a file using the "File to process" field
- Optionally check the binary display option (if available)
- Click "Send File" to upload
- View the processed file content on the results page
Supported File Types
- Text files (.txt, .html, .xml, etc.)
- Binary files (images, executables, etc.)
- Any file type up to 10KB in size
Display Modes
Text Mode
- Shows printable ASCII characters (0x20-0x80)
- Converts HTML special characters to entities
- Preserves line breaks with
<BR> tags
Binary Mode
- Hexadecimal dump format (16 bytes per line)
- ASCII representation alongside hex values
- Non-printable characters shown as dots
Development Notes
Dependencies
Error Handling
- File size limits enforced
- Invalid file descriptors handled gracefully
- Network timeout protection during initialization
Console Output
The application provides diagnostic output showing:
- Application name and NNDK revision
- POST processing events (start, variable, file, end)
- Network initialization status
- System diagnostics (if enabled)
Limitations
- Maximum file size: 10KB
- Single file upload per request
- No persistent file storage
- Files are processed in memory only
Security Considerations
- File size limits prevent memory overflow
- HTML encoding prevents XSS attacks
- No file system access beyond temporary processing
- Network access controls should be implemented at infrastructure level
Troubleshooting
Common Issues
- File not uploading: Check file size (<10KB) and network connectivity
- Display issues: Verify HTML encoding and browser compatibility
- Network problems: Confirm DHCP configuration and device connectivity
Debug Features
- Console logging for POST events
- System diagnostics output
- Network initialization feedback