A high-performance file transfer system built with .NET 9 and gRPC
π Quick Start β’ π Documentation β’ π€ Contributing
- π Bidirectional File Transfer: Upload and download files using gRPC streaming
- π¦ Chunked Transfer: Efficient handling of large files through 2KB chunks
- π Real-time Progress: Live progress tracking during file operations
- π Cross-platform: Works on Windows, macOS, and Linux
- β‘ High Performance: Built with .NET 9 and modern gRPC implementation
- ποΈ Clean Architecture: Separation between server and client applications
graph TB
subgraph "Client Applications"
UC[Upload Client<br/>Console App]
DC[Download Client<br/>Console App]
end
subgraph "gRPC Server"
GS[FileTransportService]
FS[wwwroot/files/]
end
subgraph "Protocol Definition"
PB[FileTransport.proto]
end
UC -->|FileUpload Stream| GS
DC -->|FileDownload Request| GS
GS -->|Store Files| FS
GS -->|Stream Files| DC
PB -.->|Defines Contract| UC
PB -.->|Defines Contract| DC
PB -.->|Defines Contract| GS
style UC fill:#e1f5fe
style DC fill:#e8f5e8
style GS fill:#fff3e0
style PB fill:#f3e5f5
- .NET 9: Latest framework with improved performance
- gRPC: High-performance RPC framework
- Protocol Buffers: Efficient binary serialization
- ASP.NET Core: Web hosting and dependency injection
- .NET 9 SDK
- Visual Studio 2022 or VS Code
- Git
git clone https://github.com/yourusername/grpc-file-streaming.git
cd grpc-file-streamingcd GrpcFileStreaming.Server
dotnet restore
dotnet runServer will start on http://localhost:5026
# Open new terminal
cd GrpcFileStreaming.Client
dotnet restore
dotnet run# Open another terminal
cd grpcDownloadClient
dotnet restore
dotnet runservice FileService {
rpc FileDownload (FileInfo) returns (stream BytesContent);
rpc FileUpload (stream BytesContent) returns (google.protobuf.Empty);
}
message FileInfo {
string fileName = 1;
string fileExtension = 2;
}
message BytesContent {
int64 fileSize = 1;
bytes buffer = 2;
int32 readedByte = 3;
FileInfo info = 4;
}π¦ grpc-file-streaming/
βββ π₯οΈ GrpcFileStreaming.Server/
β βββ π Services/
β β βββ FileTransportService.cs # Core gRPC service implementation
β βββ π‘ Protos/
β β βββ FileTransport.proto # Protocol buffer definition
β βββ π wwwroot/
β β βββ files/ # File storage directory
β βββ βοΈ Program.cs # Server configuration
β βββ π¦ GrpcFileStreaming.Server.csproj
βββ π€ GrpcFileStreaming.Client/
β βββ π Program.cs # Upload client
β βββ π¦ GrpcFileStreaming.Client.csproj
βββ π₯ grpcDownloadClient/
β βββ π Program.cs # Download client
β βββ π¦ grpcDownloadClient.csproj
βββ π README.md
var upload = client.FileUpload();
byte[] buffer = new byte[2048];
int bytesRead;
while ((bytesRead = await fileStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
var content = new BytesContent
{
FileSize = fileStream.Length,
Buffer = ByteString.CopyFrom(buffer, 0, bytesRead),
ReadedByte = bytesRead,
Info = new FileInfo
{
FileName = Path.GetFileNameWithoutExtension(file),
FileExtension = Path.GetExtension(file)
}
};
await upload.RequestStream.WriteAsync(content);
// Progress calculation
var progress = (double)totalUploaded / fileStream.Length * 100;
Console.WriteLine($"Upload Progress: {progress:F1}%");
}var request = client.FileDownload(fileInfo);
while (await request.ResponseStream.MoveNext(token))
{
var buffer = request.ResponseStream.Current.Buffer.ToByteArray();
await fileStream.WriteAsync(buffer, 0, buffer.Length);
// Progress tracking
var percent = Math.Round((double)downloadedBytes / totalSize * 100, 2);
Console.WriteLine($"Download Progress: {percent}%");
}- Chunk Size: 2KB for optimal memory usage
- Streaming: Real-time data transfer without loading entire files into memory
- Progress Tracking: Percentage-based progress reporting
- Async Operations: Non-blocking I/O operations
- File Storage: Local file system storage in
wwwroot/files/
Run the applications:
# Test server
cd GrpcFileStreaming.Server
dotnet run
# Test upload client
cd ../GrpcFileStreaming.Client
dotnet run
# Test download client
cd ../grpcDownloadClient
dotnet run- Authentication & Authorization: JWT token implementation
- Database Integration: File metadata storage with Entity Framework
- Web UI: Browser-based file management interface
- Docker Support: Containerized deployment
- Resumable Uploads: Support for interrupted transfer recovery
- File Compression: Built-in compression for better performance
- Load Balancing: Multiple server instance support
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- gRPC Team for the excellent framework
- .NET Team for continuous improvements
- Protocol Buffers for efficient serialization
β Star this repository if you find it helpful!