开发者

ASP.Net MVC 3: Get length in kb of an WebImage

开发者 https://www.devze.com 2023-03-15 17:38 出处:网络
I 开发者_如何学编程have a small form that allow user to upload an avatar I used WebImage to get the file uploaded from client (WebImage.GetImageFromRequest() that return WebImage object), in the serve

I 开发者_如何学编程have a small form that allow user to upload an avatar I used WebImage to get the file uploaded from client (WebImage.GetImageFromRequest() that return WebImage object), in the server i have to check to size of avatar, how can i do that?

Edit: I mean the length of it, the length in kb


http://msdn.microsoft.com/en-us/library/system.web.helpers.webimage(v=vs.99).aspx

The WebImage class has properties that expose the Height and Width of the image in pixels. So this will give you the size of the image.

EDIT

I think this post might help you with that, but it requires you have the image saved to disk.

How to get the file size of a "System.Drawing.Image"

Additionally, you could do something like this, though it'll have some overhead as you'll be putting all of the bytes into memory...

WebImage uploadedImage = WebImage.GetImageFromRequest("somefile");
long sizeInKBytes = uploadedImage.GetBytes().Length / 1024;
0

精彩评论

暂无评论...
验证码 换一张
取 消