How can I get access to the binary stream?

Oct 28, 2008 at 2:06 PM
Hi,
With the existing ASP.NET FileUpload control I can get access to the binary file stream.  This is because we have the data going into a database rather than saved to the server. Can you advise how to accomplish this with the AJAX version?  Normally you would use something like: fuFileUploader.PostedFile.InputStream.Read()
Nov 12, 2008 at 10:20 PM
I had the same problem and there is a member variable called "FileBytes" in the FileUploaderAJAX class.  The problem is you probably don't want to use that because it requires you to call the Save() or SaveAs() method which will save it to your web server's file system and we want to save the bytes to our database.

So, my solution was to create a new method called GetBytes() that does the same thing as SaveAs() in the FileUploaderAJAX_Actions class.  I just copy and pasted SaveAs() renamed it to GetBytes() and removed the code that saves the file to the filesystem.  Of course, I also made it return the bytes that were uploaded.  

If you want to preserve much of the functionality of this control, then a lot more modification will be required.  However, I didn't want the functionality of the control showing me what file was uploaded, I just wanted it to return to the normal state after it completed the upload.  You can short circuit this by going into the OnLoad() method of the FileUploaderAjax class and changing the switch statement to call normal() instead of uploaded() if the case is clave1Values.sUploading.