Answers to these few questions would be greatly appreciated!
8 Answers, 1 is accepted
I should have kept reading before posting.
I guess the update to my question would be as follows:
If I change settings to allow a large file, is there a way to (using the telerik uploader and commands) limit a file's size allowed to be queued in a specific list?
IE: I setup an allowance of 20mb files, but in this instance of the telerik file uploader I want to cap out the allowed size at 5mb (numbers are arbitrary, no code to post as I am asking hypothetically)
You can check for the file size in the OnUpload event and cancel it when it exceeds a given limit. But there is a caveat. The file size is only available in browsers that support the new File API - Firefox 4 and Chrome.
<script type=
"text/javascript"
>
var
bytesPerMB = 1048576;
function
onUpload(e) {
// Array with information about the uploaded files
var
files = e.files;
// Check the extension of each file and abort the upload if it is not .jpg
$.each(files,
function
(file) {
if
(file.size && (file.size > 5 * bytesPerMB)) {
alert(
"File size exceeds the 5MB limit"
)
e.preventDefault();
return
false
;
}
});
}
</script>
With this in mind you should also implement a server-side validation for browsers that do not provide file size information.
Tsvetomir Tsonev
the Telerik team
Anyway, the below works for anyone scratching their head:
var bytesPerMB = 1048576;
function onUpload(e) {
// Array with information about the uploaded files
var files = e.files;
// Check the extension of each file and abort the upload if the file is larger than a prescribed size, 5MB in this case
$(files).each(function (index, file) {
if (file.size && (file.size > 5 * bytesPerMB)) {
alert("Your image is greater than 5MB in size. Please select a smaller image")
e.preventDefault();
return false;
}
});
}
I tried your code but it returns a file size of null as per the attached picture. I am using MVC 3 version for 2011 Q1. Please would you help.
This size showing null even for images with more than 500kb in size.
Thanks,
Samir
From your screenshot it looks that you are using Internet Explorer. As Tsvetomir said the file size is available only in browsers that support the new File API - Firefox 4 and Chrome.
Atanas Korchev
the Telerik team
I'm facing the same issue.
In order to get the file size in IE, what approach should I follow.
Thanks
Gurpreet
File size is not supported in Internet Explorer due to lacking implementation of the required HTML5 API. Unfortunately we cannot offer a workaround for retrieving the file size on the client-side. You need to perform file size checks on the server side.
Regards,Atanas Korchev
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>