Note that there are some explanatory texts on larger screens.

plurals
  1. POWeb API controller POST attempts a file download on client
    primarykey
    data
    text
    <p>I've created an Web API controller in my MVC project. Whenever I try to POST to this controller, it try's to initiate a File download, and I am not sure why. It happens if I navigate to the API controller via URL or if it's done via a Form post. </p> <p>It's a very simple scenario where an File is to be uploaded via a post.</p> <p>Here is the controller code. Any ideas?</p> <pre><code>public class UploadController : ApiController { public async Task&lt;List&lt;string&gt;&gt; Post() { // Verify that this is an HTML Form file upload request if (!Request.Content.IsMimeMultipartContent("form-data")) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } // Create a stream provider for setting up output streams that saves the output under c:\tmp\uploads // If you want full control over how the stream is saved then derive from MultipartFormDataStreamProvider // and override what you need. MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider("c:\\tmp\\"); var task = await Request.Content.ReadAsMultipartAsync(streamProvider); return new List&lt;string&gt;(); } </code></pre> <p>Here is the client code:</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;HTML5 Multiple File Upload Sample&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="http://localhost:8080/api/upload" enctype="multipart/form-data" method="POST"&gt; What is your name? &lt;input name="submitter" size="40" type="text"&gt;&lt;br&gt; What files are you uploading? &lt;input name="data" type=file multiple&gt; &lt;br&gt; &lt;input type="submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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. 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