Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ gRPC File Streaming System

gRPC .NET C# License

A high-performance file transfer system built with .NET 9 and gRPC

πŸš€ Quick Start β€’ πŸ“– Documentation β€’ 🀝 Contributing


πŸš€ Features

  • πŸ”„ 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

πŸ—οΈ System Architecture

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
Loading

πŸ› οΈ Technology Stack

  • .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

πŸ“‹ Prerequisites

⚑ Quick Start

1️⃣ Clone Repository

git clone https://github.com/yourusername/grpc-file-streaming.git
cd grpc-file-streaming

2️⃣ Start the Server

cd GrpcFileStreaming.Server
dotnet restore
dotnet run

Server will start on http://localhost:5026

3️⃣ Upload a File

# Open new terminal
cd GrpcFileStreaming.Client
dotnet restore
dotnet run

4️⃣ Download a File

# Open another terminal
cd grpcDownloadClient
dotnet restore
dotnet run

πŸ“Š API Reference

gRPC Service Definition

service 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;
}

πŸ“ Project Structure

πŸ“¦ 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

πŸ’» Usage Examples

Upload Example

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}%");
}

Download Example

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}%");
}

πŸ“ˆ Current Features & Performance

  • 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/

πŸ§ͺ Testing

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

πŸ›£οΈ Future Enhancements (Roadmap)

  • 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

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • gRPC Team for the excellent framework
  • .NET Team for continuous improvements
  • Protocol Buffers for efficient serialization

⭐ Star this repository if you find it helpful!

About

High-performance file transfer system with .NET 9 and gRPC streaming

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages