Solved

Check if a file has been selected with BlueImp's JQuery File Upload

Posted on 2013-12-29
1
1,969 Views
Last Modified: 2014-01-11
Hello, I'm using BlueImp's JQuery File Upload plugin (https://github.com/blueimp/jQuery-File-Upload) and although everything is working properly I don't know how to check if the input has a file. How can I do this?

This is my html:

<span class="btn fileinput-button">
    <i class="icon-camera"></i>
    <input id="filUserNewPostImageUpload" name="file" type="file" />
</span>

Open in new window


This is the jquery:

$("#filUserNewPostImageUpload").fileupload({
   url: "/userattachment/upload/",
   dataType: "json",
   start: function(e){
      $("#hidUserNewPostAttachment").val("");
   },
   done: function (e, data) {

      if(data.result.result == "success"){
         // This returns an empty string even when a file has been uploaded successfully
         console.log($("#filUserNewPostImageUpload").val());  
      }
   }
});

Open in new window


Thanks!
0
Comment
Question by:ivanblue
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39744695
What about :
    change: function(e) {
        alert("file change");
    }

Open in new window


$("#filUserNewPostImageUpload").fileupload({
   url: "/userattachment/upload/",
   dataType: "json",
   start: function(e){
      $("#hidUserNewPostAttachment").val("");
   },
   done: function (e, data) {

      if(data.result.result == "success"){
         // This returns an empty string even when a file has been uploaded successfully
         console.log($("#filUserNewPostImageUpload").val());  
      }
   },
    change: function(e) {
        alert("file change");
    }
});

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now