I'm using ASP.NET Web Pages to create a form in which I can select an image. I want to then resize the image into various different sizes so that I can display them on my website.
This is working for smaller images (in filesize), but the images I want to resize are from my digital SLR and they can be as large as 14MB per jpeg. I got the following error...
Maximum request length exceeded.
I added a web.config
with the following code:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime maxRequestLength="20480" />
</system.web>
</configuration>
I no longer get the error, but it doesn't actually do anything. It still works with smaller images.
I've used the tutorial here: http://www.asp.net/web-pages/tutorials/files,-images,-and-media/9-working-with-images
My code is as follows:
@{ WebImage photo = null;
var newFileName = "";
var imagePath = "";
var imageThumbPath = "";
if(IsPost){
photo = WebImage.GetImageFromRequest();
if(photo != null){
newFileName = "Original_" + Path.GetFileName(photo.FileName);
imagePath = @"images" + newFileName;
photo.Save(@"~" + imagePath);
newFileName = "Thumbnail_" + Path.GetFileName(photo.FileName);
imagePath = @"images" + newFileName;
photo.Resize(width: 60, height: 60, preserveAspectRatio: true, preventEnlarge: true);
photo.Save(@"~" + imagePath);
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>Resizing Image</title>
</head>
<body>
<h1>Thumbnail Image</h1>
<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<legend> Creating Thumbnail Image </legend>
<label for="Image">Image</label>
<input type="file" name="Image" />
<br/>
<input type="submit" value="Submit" />
</fieldset>
</form>
</body>
</html>
Any ideas why it's not working for larger images. Any help appreciated!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…