Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

ImageField Content Size

Avatar

Level 3

Is there a way for me to know how large (in Bytes, etc) an image is within an imageField?

Right now users can only insert images that are less than 1MB and I need to know how to test for that.

All feedback is appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi David.

Paul's and Marcel's solutions will work for you.

A couple of things to look at:

1) Your naming convention includes the minus sign twice. This is why the xfa.resolveNode is used in some of the solutions above. If you insert the real image field's name straight into Marcel's validation script it may throw up an error. You could do a couple of things:

  • Because in this case the script is in one of its own events, you could change the object name to "this" (Javascript) or "$" (FormCalc).
  • resolve the name of the object in the script, e.g. xfa.resolveNode("EX-Image-1"). You could set up a variable for this at the start of the script, e.g.  var vImage = xfa.resolveNode("EX-Image-1"); and then use vImage in the actual script.
  • Change the name of your objects; either deleting the minus sign (exImage1) or substituting the minus for an underscore (EX_Image_1). This way the object(s) will not have to be resolved in order to be used in script.

Because you do not already have alot of script referring to the image fields, I would be inclined to change the object names. This way your new scripting is less likely to have problems. Otherwise bear in mind that you will need to resolve the name each time you refer to the object in script.

A handy way to ensure that you have the correct object name in your script is get LC to insert the name for you. When the script window is active, click in the location in the script where you want to refer to a field. Then hover over the field you want to reference and hold "Control". The mouse will change to a "V". Click the field and LC will insert the object name (including subform name(s)) for you. It also automatically deals with issues where the name needs to be resolved. Like above or if there are multiple objects with the same name.

2) Marcel's solution looks like JavaScript ({} and ; in the script), so you might try and change the language.

Hope this helps.

Niall

View solution in original post

10 Replies

Avatar

Former Community Member

The image is stored as base64 encoded so this technique may return an inacurate answer but it is something to go on:

Try this:

ImageFieldName.value.image.value.length

Avatar

Level 3

This is helpful. Thank you.

I'm using an imageField called dhImage. What would the JavaScript look like for checking the image size (needs to be less than 1MB) and then alerting the user if it's over?

I'm sure the script is stright-forwrd, but I'm a newbie and would appreciate your help.

Would I put the JavaScript in the click event?

Avatar

Former Community Member

This concept can only be applied after the image is called not before so I do not think it will do what you ask. I was thinking the limitation was for submitting not for attaching the images.

Sorry for the confusion

Paul

Avatar

Level 10

Hi David,

You could set up an invisible numeric field and then have the following Javascript in the mouseUp event of the image field:


NumericField1.rawValue = xfa.resolveNode("dhImage").value.image.value.length;

I have tested it here with some photos and generally a 1Mb image is resulting in a 1,400,000 number in the field.

You could then set up an app.alert message to the user if this value exceeds this limit and then set the imageField to null.

You would need a numeric field for every image field and it would need some testing to make sure the 1,400,000 was a realistic limit for a 1Mb photograph.

Good luck,

Niall

Avatar

Employee

You could also use the valudate event of the image field.

Paste this script on the validate event of your dhImage object in FormCalc language:

if(dhImage.value.image.value.length > 1440462)
{
    this.validationMessage = "Image larger than 1 Meg. Please select another image.";   
    0;
}

Avatar

Level 3

Thank you Marcel -- this LOOKS like we are on the right track.

I pasted the code into the validate event, using FormCalc and got this error:

Error:syntax error near token "Value" on line 1, column 20

When I put the real name of my field in the function, column 20 refers to the end of the first "value."

Any ideas

Avatar

Level 3

Hi Niall,

It looks as though Marcel's validate routine would be the simpliest code to execute and manage. I just need to get the syntax correct so that it works.

Thank you for your idea.

Avatar

Correct answer by
Level 10

Hi David.

Paul's and Marcel's solutions will work for you.

A couple of things to look at:

1) Your naming convention includes the minus sign twice. This is why the xfa.resolveNode is used in some of the solutions above. If you insert the real image field's name straight into Marcel's validation script it may throw up an error. You could do a couple of things:

  • Because in this case the script is in one of its own events, you could change the object name to "this" (Javascript) or "$" (FormCalc).
  • resolve the name of the object in the script, e.g. xfa.resolveNode("EX-Image-1"). You could set up a variable for this at the start of the script, e.g.  var vImage = xfa.resolveNode("EX-Image-1"); and then use vImage in the actual script.
  • Change the name of your objects; either deleting the minus sign (exImage1) or substituting the minus for an underscore (EX_Image_1). This way the object(s) will not have to be resolved in order to be used in script.

Because you do not already have alot of script referring to the image fields, I would be inclined to change the object names. This way your new scripting is less likely to have problems. Otherwise bear in mind that you will need to resolve the name each time you refer to the object in script.

A handy way to ensure that you have the correct object name in your script is get LC to insert the name for you. When the script window is active, click in the location in the script where you want to refer to a field. Then hover over the field you want to reference and hold "Control". The mouse will change to a "V". Click the field and LC will insert the object name (including subform name(s)) for you. It also automatically deals with issues where the name needs to be resolved. Like above or if there are multiple objects with the same name.

2) Marcel's solution looks like JavaScript ({} and ; in the script), so you might try and change the language.

Hope this helps.

Niall

Avatar

Level 2

Hi,

I have created few forms in Adobe Output Designer (IFD). I have converted those Adobe Output Designer (IFD) files to Adobe Livecycle ES (XDP). I have successful converted those IFD files to XDP, but I found some alignment problems in XDP files.

It’s not matching 100% with the IFD files.

Any suggestions are welcome.....

Regards,

Jayakumar Sriram

Avatar

Level 3

Thank you Niall (Paul & Marcel) for your detailed and thoughtful response. That is really appreciated.

Because I'm a newbie, I didn't know enough to avoid dashes, when creating fields. To rename them at this stage in the game would be long and error-prone. As a result, I setup a variable as you suggested.

Here is the JavaScript code that I ended up with.

var vImage = xfa.resolveNode("NA-Image-1");

if(vImage.value.image.value.length > 1440462)

{

    this.validationMessage = "Image larger than 1 Meg. Please resize your image.";   

    0;

}