Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax uploading and ASP.NET
    text
    copied!<p>I'm trying to upload some text content via ajax, that will be parsed later. That is my Javascript code: </p> <pre><code> $("#fuFile").change(function () { var fileInput = document.getElementById("fuFile"); var file = fileInput.files[0]; var formdata = new FormData(); formdata.append('file', file); var xhr = new XMLHttpRequest(); xhr.open("POST", 'testhandler.ashx', true); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.setRequestHeader("X-File-Name", file.name); xhr.setRequestHeader("Content-Type", "application/octet-stream"); xhr.send(formdata); }); </code></pre> <p>Where <code>fuFile</code> is my file input, and <code>testhandler.ashx</code> is the server handler that gets the uploaded file. (I actually use another handler to parse the file content.) </p> <p>BUT when I try to do this: </p> <pre><code>HttpFileCollection fc = context.Request.Files; </code></pre> <p>It returned no files. But Works in IE for some reason.</p> <p>But when I try to get the input stream:</p> <pre><code> StreamReader stream = new StreamReader(context.Request.InputStream); string text = stream.ReadToEnd(); </code></pre> <p>The <code>text</code> variable become (Http Headers) + File Content.</p> <pre><code>------WebKitFormBoundaryx16Mw7tnG6JeflIB\r\nContent-Disposition: form-data;name=\"file\"; filename=\"teste export.CSV\"\r\nContent-Type: application/vnd.ms-excel(..file content..) </code></pre> <p>That's OK, but I've used this plugin: <a href="http://valums.com/ajax-upload/" rel="nofollow">http://valums.com/ajax-upload/</a></p> <p>And the plugin returned me only the file content, in witch I could get the content via InputStream, I didn't received any HTTP header.</p> <p>That's PERFECT, but I want to make a Upload script without using plugins. Just upload and parse, returning some results. Simple and fast</p> <p>So, My question is: <strong>How to get the file content, uploaded by Ajax XHR, getting ONLY the file content, in any browser?</strong></p>
 

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