public override async Task Download(V1.FileStreaming.FileInfo request, IServerStreamWriter <BytesContent> responseStream, ServerCallContext context)
        {
            var path = GetPath();

            try
            {
                using FileStream fileStream = new FileStream($"{path}/{request.FileName}{request.FileExtension}", FileMode.Open, FileAccess.Read);

                byte[] buffer = new byte[2048];

                BytesContent content = new BytesContent
                {
                    FileSize = fileStream.Length,
                    Info     = new V1.FileStreaming.FileInfo {
                        FileName = "video", FileExtension = ".mp4"
                    },
                    ReadedByte = 0
                };

                while ((content.ReadedByte = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    content.Buffer = ByteString.CopyFrom(buffer);
                    await responseStream.WriteAsync(content);
                }

                fileStream.Close();
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 2
0
        private static async Task FileStreamingDownload()
        {
            var    channel         = GrpcChannel.ForAddress("https://*****:*****@$ "{downloadPath}\{request.ResponseStream.Current.Info.FileName}{request.ResponseStream.Current.Info.FileExtension}", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
                    fileStream.SetLength(request.ResponseStream.Current.FileSize);
                }

                var buffer = request.ResponseStream.Current.Buffer.ToByteArray();
                await fileStream.WriteAsync(buffer, 0, request.ResponseStream.Current.ReadedByte);

                Console.WriteLine($"{Math.Round(((chunkSize += request.ResponseStream.Current.ReadedByte) * 100) / request.ResponseStream.Current.FileSize)}%");
            }