Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try using a simple <a href="https://msdn.microsoft.com/en-us/library/system.net.http.httpresponsemessage.aspx" rel="noreferrer"><code>HttpResponseMessage</code></a> with its <code>Content</code> property set to a <a href="https://msdn.microsoft.com/en-us/library/system.net.http.streamcontent.aspx" rel="noreferrer"><code>StreamContent</code></a>:</p> <pre><code>// using System.IO; // using System.Net.Http; // using System.Net.Http.Headers; public HttpResponseMessage Post(string version, string environment, string filetype) { var path = @"C:\Temp\test.exe"; HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); var stream = new FileStream(path, FileMode.Open, FileAccess.Read); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return result; } </code></pre> <p>A few things to note about the <code>stream</code> used:</p> <ul> <li><p>You must not call <code>stream.Dispose()</code>, since Web API still needs to be able to access it when it processes the controller method's <code>result</code> to send data back to the client. Therefore, do not use a <code>using (var stream = …)</code> block. Web API will dispose the stream for you.</p></li> <li><p>Make sure that the stream has its current position set to 0 (i.e. the beginning of the stream's data). In the above example, this is a given since you've only just opened the file. However, in other scenarios (such as when you first write some binary data to a <code>MemoryStream</code>), make sure to <code>stream.Seek(0, SeekOrigin.Begin);</code> or set <code>stream.Position = 0;</code></p></li> <li><p>With file streams, explicitly specifying <a href="https://msdn.microsoft.com/en-us/library/system.io.fileaccess.aspx" rel="noreferrer"><code>FileAccess.Read</code></a> permission can help prevent access rights issues on web servers; IIS application pool accounts are often given only read / list / execute access rights to the wwwroot.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload