My model class looks like this
public Stream FileStream { get; set; }
public string FileName { get; set; }
public string ContentType { get; set; }
Is it possible to return this model to webapi?
My model class looks like this
public Stream FileStream { get; set; }
public string FileName { get; set; }
public string ContentType { get; set; }
Is it possible to return this model to webapi?
A Stream is just a pointer to some actual resource. If you want to send this to the response and be able to serialize it you could use a byte array.
Or event better, write the Stream to the response and then use standard HTTP headers for the 2 other properties:
Content-Type: application/pdf
Content-Disposition: attachment; filename=report.pdf
... the actual content comes here
You could also consider writing a custom MediaTypeFormatter
to achieve this as shown in this article
.
No. This cannot be automatically serialised. But returning a stream is easy. See here.