Solved

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

Posted on 2013-12-29
1
2,011 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

778 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