How to convert IFormFile to Byte array?

winanjaya 146 Reputation points
2023-03-22T11:48:31.06+00:00

Hi

How to convert iFormFile to Byte array?, I have tried the below, but it keeps give me Cannot access a disposed object. Object name: 'FileBufferingReadStream

                    foreach (var formFile in supportingFiles)
                    {
                        long fileSize = formFile.Length;
                        string fileType = formFile.ContentType;

                        if (fileSize > 0)
                        {
                            using (var stream = new MemoryStream())
                            {
                                formFile.CopyTo(stream);
                                var bytes = stream.ToArray();

                                // do some stuffs
                                
                               
                                 
                                }
                            }
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,503 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.