0

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?

4

2 回答 2

1

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.

于 2013-09-05T11:40:54.800 回答
0

No. This cannot be automatically serialised. But returning a stream is easy. See here.

于 2013-09-05T12:16:23.297 回答