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
});
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");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.