pippuccio76
pippuccio76

Reputation: 31

Blueimp get uploaded filename

I need to recover the name or the url of my uploaded file:

<script>
    $('#fileupload').fileupload({

        complete: function (e, data) {
            $.each(data.files, function (index, file) {
              alert(file.name);
            });
        }
        });
</script>

but in the alert i have in console :

jquery.js:358 Uncaught TypeError: Cannot read property 'length' of undefined

how solve it ?

Upvotes: 1

Views: 1857

Answers (2)

Dar&#237;o Pm
Dar&#237;o Pm

Reputation: 159

Try this instead:

$('#fileupload').on("fileuploaddone", function (e, data) {
    $.each(data.files, function (index, file) {
        alert(file.name);
    });
});

Also other than fileuploaddone "events" can be used. See:

https://github.com/blueimp/jQuery-File-Upload/wiki/Options#callback-options

Upvotes: 2

Periklis Douvitsas
Periklis Douvitsas

Reputation: 2491

most probably you do not return the name of the files from the server. The response should be of the form

{ 
  files:
    [
      {
        url: "http://url.to/file/or/page",
        thumbnail_url: "http://url.to/thumnail.jpg ",
        name: "thumb2.jpg",
        type: "image/jpeg",
        size: 46353,
        delete_url: "http://url.to/delete /file/",
        delete_type: "DELETE"
      }
    ]
}

Have a look at the following url to see the response https://github.com/blueimp/jQuery-File-Upload/wiki/JSON-Response

make sure than in the json that you return, you return the name property and that you return the whole json message like the format above.

let me know if this helped

Upvotes: 1

Related Questions