NIHVIVO-161 - Test that the image to be uploaded is at least as large as the thumbnail will be.
This commit is contained in:
parent
f0900aa262
commit
ec15ba5a49
2 changed files with 23 additions and 7 deletions
|
@ -283,8 +283,18 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
|
|||
|
||||
// Did they provide a file to upload? If not, show an error.
|
||||
FileItem fileItem;
|
||||
Dimensions mainImageSize;
|
||||
try {
|
||||
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) {
|
||||
String thumbUrl = getThumbnailUrl(entity);
|
||||
String message = e.getMessage();
|
||||
|
@ -305,8 +315,6 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
|
|||
entity = getWebappDaoFactory().getIndividualDao().getIndividualByURI(
|
||||
entityUri);
|
||||
|
||||
Dimensions mainImageSize = helper.getMainImageSize(entity);
|
||||
|
||||
// Go to the cropping page.
|
||||
return showCropImagePage(vreq, entity, getMainImageUrl(entity),
|
||||
mainImageSize);
|
||||
|
@ -636,6 +644,11 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
|
|||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dimensions[width=" + width + ", height=" + height + "]";
|
||||
}
|
||||
}
|
||||
|
||||
private static interface ResponseValues {
|
||||
|
|
|
@ -407,14 +407,17 @@ public class ImageUploadHelper {
|
|||
InputStream stream = null;
|
||||
try {
|
||||
stream = fileStorage.getInputStream(uri, filename);
|
||||
BufferedImage image = ImageIO.read(stream);
|
||||
return new Dimensions(image.getWidth(), image.getHeight());
|
||||
BufferedImage i = ImageIO.read(stream);
|
||||
Dimensions size = new Dimensions(i.getWidth(), i.getHeight());
|
||||
log.debug("main image size is " + size);
|
||||
return size;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.warn("No main image file for '" + showUri(entity) + "'; name='"
|
||||
log.error(
|
||||
"No main image file for '" + showUri(entity) + "'; name='"
|
||||
+ filename + "', bytestreamUri='" + uri + "'", e);
|
||||
return new Dimensions(0, 0);
|
||||
} catch (IOException e) {
|
||||
log.warn(
|
||||
log.error(
|
||||
"Can't read main image file for '" + showUri(entity)
|
||||
+ "'; name='" + filename + "', bytestreamUri='"
|
||||
+ uri + "'", e);
|
||||
|
|
Loading…
Add table
Reference in a new issue