0

I want to read in an image data and send the source of the image so the server. I was using a FileReader that creates a Base64-String. As the String can become very, I want to send the image source as binary data, how can I do it?

currently done via base64:

var reader = new FileReader();

reader.readAsDataURL( file );

reader.onloadend = function(){

   var source = this.result; //i need to send this to the server
}

1 Answer 1

1

Try this:

Javascript:

$("#browse").change(function () {
    var files = this.files;
    var reader = new FileReader();
    var name = this.value;
    reader.onload = function (e) {
        $("#preview").append("<a>'" + name + "'</a><img src='" + e.target.result + "' width='30' height='30' />");
        alert(e.target.result);
    };
    reader.readAsDataURL(files[0]);
});

HTML:

<input type="file" id="browse" />
<div id="preview"></div>

I think, you can send e.target.result to server in the way you want to.

Working Demo: http://jsfiddle.net/ashishanexpert/3QyEB/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.