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();
–
–
–
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.