Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data from file input in JQuery

I actually have a file input and I would like to retrieve the Base64 data of the file.

I tried:

$('input#myInput')[0].files[0]  

to retrieve the data. But it only provides the name, the length, the content type but not the data itself.

I actually need these data to send them to Amazon S3

I already test the API and when I send the data through html form with encode type "multipart/form-data" it works.

I use this plugin : http://jasny.github.com/bootstrap/javascript.html#fileupload

And this plugins gives me a preview of the picture and I retrieve data in the src attribute of the image preview. But when I send these data to S3 it does not work. I maybe need to encode the data like "multipart/form-data" but I don't know why.

Is there a way to retrieve these data without using an html form?

like image 679
kschaeffler Avatar asked Sep 05 '12 12:09

kschaeffler


People also ask

How to get the value of file input in JQuery?

var d = document. getElementById('AttachmentFile'); alert(d. value);

How do you take input from a file?

File Input and Output in C 1) Create a variable to represent the file. 2) Open the file and store this "file" with the file variable. 3) Use the fprintf or fscanf functions to write/read from the file.

How to read data from file JavaScript?

To read a file, use FileReader , which enables you to read the content of a File object into memory. You can instruct FileReader to read a file as an array buffer, a data URL, or text.


1 Answers

input file element:

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

get file :

var myFile = $('#fileinput').prop('files'); 
like image 94
Morilog Avatar answered Sep 19 '22 15:09

Morilog