Get binary file data sent from postman in net core web api?

Viewed 1311

How to read the video file sent from the postman in body binary... Content-Type : video/mp4 Content-Range: bytes 0-5119999/33230845 Content-Length: 5120000

 IFormFile file;

            using (var sr = new BufferedStream(Request.Body))
            {
                var byteArray = await sr.ReadAllBytes();
                var stream = new MemoryStream(byteArray);
                file = new FormFile(stream, 0, byteArray.Length, "testName", "testFileName");

                string path = $"C:\\Projects\\vid{uploadRequest.BlockId}.mp4";
                using FileStream str = new FileStream(path, FileMode.Create);
                str.Position = 0;
                await stream.CopyToAsync(str);
            }

public static async Task<byte[]> ReadAllBytes(this Stream instream)
        {
            if (instream is MemoryStream)
                return ((MemoryStream)instream).ToArray();

            await using MemoryStream memoryStream = new MemoryStream();

            await instream.CopyToAsync(memoryStream);
            return memoryStream.ToArray();
        }

When I save this file into C Disk and open it, says that: item is unplayable...

enter image description here enter image description here

0 Answers
Related