NIHVIVO-161 - Test that the image to be uploaded is at least as large as the thumbnail will be.

This commit is contained in:
jeb228 2010-07-13 16:11:21 +00:00
parent f0900aa262
commit ec15ba5a49
2 changed files with 23 additions and 7 deletions

View file

@ -283,8 +283,18 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
// Did they provide a file to upload? If not, show an error. // Did they provide a file to upload? If not, show an error.
FileItem fileItem; FileItem fileItem;
Dimensions mainImageSize;
try { try {
fileItem = helper.validateImageFromRequest(vreq); fileItem = helper.validateImageFromRequest(vreq);
mainImageSize = helper.getMainImageSize(entity);
if ((mainImageSize.height < THUMBNAIL_HEIGHT)
|| (mainImageSize.width < THUMBNAIL_WIDTH)) {
throw new UserMistakeException(
"The uploaded image should be at least "
+ THUMBNAIL_HEIGHT + " pixels high and "
+ THUMBNAIL_WIDTH + " pixels wide.");
}
} catch (UserMistakeException e) { } catch (UserMistakeException e) {
String thumbUrl = getThumbnailUrl(entity); String thumbUrl = getThumbnailUrl(entity);
String message = e.getMessage(); String message = e.getMessage();
@ -305,8 +315,6 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
entity = getWebappDaoFactory().getIndividualDao().getIndividualByURI( entity = getWebappDaoFactory().getIndividualDao().getIndividualByURI(
entityUri); entityUri);
Dimensions mainImageSize = helper.getMainImageSize(entity);
// Go to the cropping page. // Go to the cropping page.
return showCropImagePage(vreq, entity, getMainImageUrl(entity), return showCropImagePage(vreq, entity, getMainImageUrl(entity),
mainImageSize); mainImageSize);
@ -636,6 +644,11 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
this.width = width; this.width = width;
this.height = height; this.height = height;
} }
@Override
public String toString() {
return "Dimensions[width=" + width + ", height=" + height + "]";
}
} }
private static interface ResponseValues { private static interface ResponseValues {

View file

@ -407,14 +407,17 @@ public class ImageUploadHelper {
InputStream stream = null; InputStream stream = null;
try { try {
stream = fileStorage.getInputStream(uri, filename); stream = fileStorage.getInputStream(uri, filename);
BufferedImage image = ImageIO.read(stream); BufferedImage i = ImageIO.read(stream);
return new Dimensions(image.getWidth(), image.getHeight()); Dimensions size = new Dimensions(i.getWidth(), i.getHeight());
log.debug("main image size is " + size);
return size;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
log.warn("No main image file for '" + showUri(entity) + "'; name='" log.error(
+ filename + "', bytestreamUri='" + uri + "'", e); "No main image file for '" + showUri(entity) + "'; name='"
+ filename + "', bytestreamUri='" + uri + "'", e);
return new Dimensions(0, 0); return new Dimensions(0, 0);
} catch (IOException e) { } catch (IOException e) {
log.warn( log.error(
"Can't read main image file for '" + showUri(entity) "Can't read main image file for '" + showUri(entity)
+ "'; name='" + filename + "', bytestreamUri='" + "'; name='" + filename + "', bytestreamUri='"
+ uri + "'", e); + uri + "'", e);