I am using RadAsyncUpload to upload image. I wanted to added client side validation of image for validating height and width of the image. There is property MaxFileSize of this control but it validates the whole size of image, but I want to validate height and width in pixels.
Thanks in advance.
Thanks in advance.
5 Answers, 1 is accepted
0
Cat Cheshire
Top achievements
Rank 1
answered on 11 Apr 2012, 12:39 PM
I doubt that you can make this with the RadAsyncUpload.
You have to implement your own custom logic to measure the images in pixels.
You have to implement your own custom logic to measure the images in pixels.
0
Sweta
Top achievements
Rank 1
answered on 11 Apr 2012, 12:44 PM
Yes I know that some custom logic needs to be build. But how ?
0
Esteban Lezama
Top achievements
Rank 1
answered on 16 Apr 2012, 06:17 PM
This is what seems to work for me to retrieve the width and height. Remember to dispose the image. Hope this helps to get you going.
public void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
System.Drawing.Bitmap img = new System.Drawing.Bitmap(e.File.InputStream);
int h = img.Height;
int w = img.Width;
img.Dispose();
if(w > allowedWidth)
e.IsValid = false;
// etc.
}
public void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
System.Drawing.Bitmap img = new System.Drawing.Bitmap(e.File.InputStream);
int h = img.Height;
int w = img.Width;
img.Dispose();
if(w > allowedWidth)
e.IsValid = false;
// etc.
}
0
Sweta
Top achievements
Rank 1
answered on 18 Apr 2012, 07:51 AM
Hi Estaben,
Thanks for the reply. But this is server side code. How to do it clientside ?
Thanks for the reply. But this is server side code. How to do it clientside ?
0
Max
Top achievements
Rank 1
answered on 19 Apr 2012, 03:04 PM
In order to be able to do some logic with RadUploadedFile you have to postback, if I understand correctly, so save server side dimensions as esteban suggests
or
using (var image = System.Drawing.Image.FromStream(AsyncUpload.UploadedFiles[0].InputStream))
{
this.Height = image.Height;
this.Width = image.Width;
}
and access them through <%= this.Height %> in js.
If you have script resources you might want to create a custom control, where you will be directly exposing any requered variable to js through ScriptControlDescriptor.
vincexu.blogspot.com/2010/02/aspnet-ajax-scriptcontrol-tutorial.html
or
using (var image = System.Drawing.Image.FromStream(AsyncUpload.UploadedFiles[0].InputStream))
{
this.Height = image.Height;
this.Width = image.Width;
}
and access them through <%= this.Height %> in js.
If you have script resources you might want to create a custom control, where you will be directly exposing any requered variable to js through ScriptControlDescriptor.
vincexu.blogspot.com/2010/02/aspnet-ajax-scriptcontrol-tutorial.html