Reputation: 31
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
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
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