0

Is it possible convert input type = file in HTML 5 to array of bytes in Javascript? I read a few articles about that but the solutions provided don't work for me. I tried these: Getting byte array through input type = file, Return the Array of Bytes from FileReader().

I need it for my ajax post method. In ASP.NET MVC app I have ViewModel with field type of byte[] and I want to write this array to database.

Code in question:

<input type="file" id="Receipt" />                           

POST method:

$(function () {
            $("#btnregister").click(function () {     
                $.ajax(
                {
                    type: "POST",
                    url: "AddUser",
                    data: 
                        {
                            File: (?)
                        }
                });
            });
        });

Thanks for any help.

4
  • Shouldn't it be <input type="file" id="Receipt" /> ? Commented Mar 21, 2017 at 15:36
  • Yes my fault but that's not it. Commented Mar 21, 2017 at 15:48
  • Possible duplicate of Getting byte array through input type = file Commented Mar 21, 2017 at 16:54
  • No, it's not working Commented Mar 21, 2017 at 17:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.