Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Almost all libraries I've searched for require a FileStream to read excel files - none work with a MultipartReaderStream , used by MultipartSection.Body property.

Any suggestions? Basically any library that supports reading an excel file via a TextReader would work with a MultipartReaderStream , as then you can simply read the stream via the use of a StreamReader .

Not sure what your controller looks like, but that's how we do it in out project

[HttpPost("endpoint")]
[Consumes("multipart/form-data")]
public async Task<IActionResult> PostFile([FromForm(Name = "file")]IFormFile file)
    using var fileStream = file.OpenReadStream();
                we don't use model binding via IFormFile, but rather do the process explained here for uploading large files via streaming, as our files tend to be pretty big. Any ideas?
– SpiritBob
                Apr 21, 2021 at 11:29
                Ok, seems like I misunderstood the question. System.IO.FileStream is a class that is designed for physical files on the local disk. So if the library requires it, that means it is not supposed to be used in HTTP server.
– Morse
                Apr 21, 2021 at 11:46
                Are you capable of modifying the default buffer size for a IFormFile? Because by default any IFormFile larger than 64kb gets turned into a temporary file, so I'm wondering if we can increase that limit upto 10 mb's for example?
– SpiritBob
                Apr 21, 2021 at 12:19

You can turn the MultiPartSection into a FileMultipartSection via a call to AsFileSection, which now has a property FileStream you can use.

Example:

MultipartReader reader = ...
MultipartSection section = await reader.ReadNextSectionAsync();
FileMultipartSection fileSection = section.AsFileSection();

Of course, you'll need to make sure the section actually contains a file, by for example checking the content disposition.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.