Reputation: 2070
I want to restrict image upload to only jpg images using the kendo UI for ASP .NET MVC3. However, when I followed the example here,even with my manipulation below, it keeps alerting "please upload jpg image files" even when I uploaded a jpg file! In fact, it makes me select all kinds of images. How can I change it so that I can only upload jpg images and if I upload png or other type of image files, it should alert, to only upload jpg images.
I put this into one of my views:
<script>
var onSelect = function (e) {
$.each(e.files, function (index, value) {
var ok = value.extension == ".JPG"
|| value.extension == ".JPEG"
|| value.extension == ".jpg"
|| value.extension == ".jpeg";
if (value.extension != ok) {
e.preventDefault();
alert("Please upload jpg image files");
}
});
};
// initialize and configure an Upload widget with a select event handler
$("#photos").kendoUpload({
select: onSelect
});
Upvotes: 1
Views: 6278
Reputation: 9881
You have a type-o:
value.expresion == ".jpg"
Should be:
value.expression == ".jpg"
Notice you are missing an 's'
EDIT
value.extension
is a string which contains the extension. And ok
is a boolean which determines if the correct extension was provided, so what you want to use to determine if to display the alert should be displayed needs to be udpated:
if (!ok) {
e.preventDefault();
alert("Please upload jpg image files");
}
Upvotes: 3