I’m am trying to upload images on my website then post them back to my server .
To upload the images I am using the plugin found here: http://jasny.github.io/bootstrap/javascript/#fileinput
So I included the javascript and css files found here:
cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.1.3/css/jasny-bootstrap.min.css
cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.1.3/js/jasny-bootstrap.min.js
On my html page I included the following :
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 100px; height: 100px;">
<img data-src="holder.js/100%x100%" alt="...">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
<div>
<span style="background-color: #68C3A3" class="btn btn-success btn-file">
<span class="fileinput-new">Select Artist Image</span><span style="background-color: #68C3A3" class="fileinput-exists">Change</span>
<input id="inPutArtistImage" type="file" multiple>
</span>
<a href="#" class="btn btn-danger fileinput-exists" data-dismiss="fileinput">Remove</a>
</div>
</div>
Selecting and removing images works nicely .
Now with a separate button I’m trying to append the selected files to Form DATA.
$scope.UpdateChannelImages = function() {
var formData, thumbnail;
formData = new FormData();
if ($('#inPutArtistImage')[0].files && $('#inPutArtistImage')[0].files.length > 0) {
thumbnail = $('#inPutArtistImage')[0].files[0];
formData.append('inPutArtistImage', thumbnail, 'Artist' + thumbnail.name);
However I simply cannot append the files to form data:
I get this error: Cannot read property 'files' of undefined
here is the line that throws the error: if ($('#inPutArtistImage')[0].files && $('#inPutArtistImage')[0].files.length > 0) {
I need help appending the uploaded image to Form data