My asp.Net MVC app needs to store a byte array that represents a user-selected PDF file per record in the database. The SQL column is a Varbinary(max).
The approach I’m contemplating is to use Telerik’s (most awesome) KendoUI Upload control to asynchronously upload the selected PDF to the controller method. The controller method converts the PDF to bytes using classes in the System.IO namespace, and I return that byte array in a Json result. I have an event handler on the page that waits for this result, and then writes that byte array to a hidden input, which then gets saved with the rest of the record when the user clicks the save button, posting the Form back to the server.
My gut feel is that I have some nasty inefficiency here…
-
the pdf is sent to the server (probably already in some form of byte array created by the Upload control).
-
the result of the upload method returns a byte array back to the page.
-
the page then submits the form postback, containing the byte array that will be saved to the database.
My thinking is that step 3 is the only network traffic required here. Is there any way that conversion from a PDF document to a byte array can happen on the client instead? What clever JavaScript/jQuery would do this?
Here:
Change this logic to: