-
Notifications
You must be signed in to change notification settings - Fork 34
Add ability to specify URL for an image #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5aae4ba
to
f2099c6
Compare
|
||
@Override | ||
@SuppressWarnings("PMD.SignatureDeclareThrowsException") | ||
public boolean preHandle( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я дико извиняюсь, но размер этого метода абсолютно невменяем и что он делает тоже непонятно.
|
||
// TODO: add title to field that only HTTP protocol is supported | ||
// and no redirects are allowed | ||
if (!"http".equals(url.getProtocol())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we suddenly use https?
LOG.debug("getReadTimeout(): {}", conn.getReadTimeout()); | ||
|
||
// TODO: how bad is it? | ||
conn.setInstanceFollowRedirects(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very bad. We know nothing about http server. It could easily redirect us to https, for example.
|
||
try (InputStream stream = new BufferedInputStream(conn.getInputStream())) { | ||
int status = conn.getResponseCode(); | ||
if (status != HttpURLConnection.HTTP_OK) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we've got another 20x status?
|
||
String contentType = conn.getContentType(); | ||
LOG.debug("Content-Type: {}", contentType); | ||
if (!"image/jpeg".equals(contentType) && !"image/png".equals(contentType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
svg? gif?
} | ||
|
||
} catch (IOException ex) { | ||
LOG.error("Couldn't open connection: {}", ex.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here could be lots of errors — e.g. readtimeout, which actually isn't problem in connection opening
// TODO: preserve original content type | ||
@Override | ||
public String getContentType() { | ||
return "image/jpeg"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
@@ -128,13 +132,17 @@ | |||
@Size(max = MAX_SERIES_COMMENT_LENGTH, message = "{value.too-long}") | |||
private String comment; | |||
|
|||
@NotNull | |||
// @NotNull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented-out code?
@NotEmptyFilename(groups = Image1Checks.class) | ||
@NotEmptyFile(groups = Image2Checks.class) | ||
@MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Image3Checks.class) | ||
@ImageFile(groups = Image3Checks.class) | ||
private MultipartFile image; | ||
|
||
// Name of this field must match with the field name that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't it javadoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this comment intended to be not for users, but for developers.
5025118
to
5952501
Compare
6d56051
to
44e6e00
Compare
02599b6
to
adeed25
Compare
3db0f80
to
fef0609
Compare
Generated by 🚫 Danger |
65b3d89
to
e2d734d
Compare
f31a9e8
to
6103fc8
Compare
5e4a9e6
to
f53e293
Compare
f53e293
to
ea51b38
Compare
…eld. Required for adding a field for specifying image URL later. No functional changes.
ea51b38
to
9ab9fb5
Compare
Required for adding a field for specifying image URL later. No functional changes.
Merged in d839472 commit. |
TODO:
MyMultipartFile
: preserve original content type@URL
validatorimage
orimageUrl
must be specifiedimage
andimageUrl
cannot be specified at the same timeDownloadImageInterceptor
: make URLs and fields configurable/series/{id}
pageHttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM
separately@NotEmptyFilename
validatorAddressed to #199