Generator-jhipster: Image Size validation in Angular

Created on 12 Sep 2019  ·  13Comments  ·  Source: jhipster/generator-jhipster

Overview of the feature request

Can we have image size validation in Angular generated code. We want to restrict user uploading image of more than 3 mb.

Motivation for or Use Case

Restricting user to upload very big image unknowingly.

  • [x] Checking this box is mandatory (this is just to show you read everything)
area wont-fix front

All 13 comments

I think this is more of a very specific customization, I don't think this should go into the generator... + if we do that for Angular we would also need a backend validation, a JDL improvement to support that kind of validation, that can be a lot of work.

@jhipster/developers WDYT ?

Not only for Angular, but for React and Vue.js too, so agree with you @wmarques

@caffeinecoders :

  • can you show us in a sample project on GitHub that it's not a lot of work, not a lot of code to maintain
  • if it's simple, do you want to contribute to provide this feature ?

Otherwise, let's not support it in generator-jhipster

Hello, @wmarques & @pascalgrimaud, this feature used to be there earlier but seems to be removed now in latter version. We are providing feature to upload images in the entity forms, not sure why size validation is not required.

Just tried right now:

================= Toto =================
Fields
name (String) required


Generating field #2

? Do you want to add a field to your entity? Yes
? What is the name of your field? picture
? What is the type of your field? [BETA] Blob
? What is the content of the Blob field? An image
? Do you want to add validation rules to your field? Yes
? Which validation rules do you want to add? (Press <space> to select, <a> to toggle all, <i> t
o invert selection)
❯◯ Required
 ◯ Unique

The validation rules for Blob are:

  • Required
  • Unique

this feature used to be there earlier but seems to be removed now in latter version

In which version of JHipster do you have size validation for Blob ?

Kindly check Jhipster version 3.5 for example, it used to have this validation. But what I really want to request is to consider, having this size validation as part of Jhipster module, I do believe it is useful.

Still, if you think this doesn't align with your vision of Jhipster, I respect it then :)

You're right @caffeinecoders
Just tried with 3.5.0 and we have this validation:

➜ yo jhipster:entity Toto

The entity Toto is being created.


Generating field #1

? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? No

================= Toto =================
Fields
name (String) 


Generating field #2

? Do you want to add a field to your entity? Yes
? What is the name of your field? picture
? What is the type of your field? [BETA] Blob
? What is the content of the Blob field? An image
? Do you want to add validation rules to your field? Yes
? Which validation rules do you want to add? 
 ◯ Required
❯◯ Minimum byte size
 ◯ Maximum byte size

So we did something wrong in our entity sub generator.
I'm adding a bug bounty on this, as it's a regression.

I would like to taking this one if @caffeinecoders is not already working on it.
As I understand we need to fix this feature on Angular, Spring validation, React (this is a real new feature) and maybe in the VueJs part.

Have a look at https://github.com/jhipster/generator-jhipster/blob/master/generators/entity/prompts.js#L750
I think the byte[] is missing for unknown reasons... maybe during some refactoring.

The front should contain the logic, but it needed to be tested -> it's probably the biggest part

It seems that this validation was removed in https://github.com/jhipster/generator-jhipster/pull/7872 on purpose, because

the server can't check the size of the blob before downloading it completely.

So it's not easy, as we can think. Maybe we should test if we could do it now or close this issue and admit this has already been resolved by #7872

Nice catch @clement26695
So it has been removed intentionaly. Maybe it's not a good idea to reintroduce this feature again

I'm closing this as it has been removed intentionaly for technical reasons.

@caffeinecoders maybe have a look at https://github.com/Blackdread/rest-filter/tree/master/src/main/java/org/blackdread/lib/restfilter/spring/validation
Copy to your code if you don't want the dependency.
The file is still uploaded to "temp" folder of server but at least you have validation before the REST controller is called.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pascalgrimaud picture pascalgrimaud  ·  3Comments

marcelinobadin picture marcelinobadin  ·  3Comments

DanielFran picture DanielFran  ·  3Comments

sdoxsee picture sdoxsee  ·  4Comments

frantzynicolas picture frantzynicolas  ·  3Comments