I am creating a service in C# that is to be used by an ASP.Net Web API that will process and store files.
As part of the Web API I take the file(s) and store them in MemoryStream
s which are then passed through to a service for actual processing and storage.
Part of the service will be to generate a new filename for each of the files.
so that leads me to the question, is it possible to find out what file type/extension the file was now that it's in a MemoryStream?
No for extension, you can guess type:
Unless content of the file somehow contains name/extension MemoryStream
by itself does not contain any information about original file name.
You may try to detect type of the file (many formats have magic number/signature in the beginning for example) by reading some/all content of the stream.
There are also several similar questions like Using .NET, how can you find the mime type of a file based on the file signature not the extension (discusses usage of UrlMon to detect type).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With