Jump to content

Need easy way to recognize PNG in container


K1200

This topic is 3009 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have an instance where a container field is occupied by an image of unknown type.  It might have been inserted or pasted in ... or imported.

It will be accepted for further processing only if it's a PNG.

How can I easily determine that?  When I look at the actual header bytes of the file (after exporting it), "PNG" is clearly visible.  Yet I wasn't able to get those first 4 bytes with a Left ( text ; 4 ) directly from the container.  Is there a way to do that?

Thanks in advance for any help.

565f5a36ced8b_PNGHeaderBytes.PNG.028bf42

 

Edited by K1200
Link to comment
Share on other sites

Thanks for the response ... but I had looked for some definitive image attribute and couldn't spot one.  Did I miss it?

filename seems to only apply to inserted files and not to pasted images.  But I'll try some additional searches.

Link to comment
Share on other sites

What do you get when you put this in Data Viewer?

RightWords ( GetContainerAttribute ( yourTable::yourContainer ; "filename" ) ; 1 )

 

Note - don't use Get ( FileName ) ... type the literal text just as it shows "filename" ...

It works when I drag an image into the container and also works when I use Insert.

Edited by LaRetta
Link to comment
Share on other sites

I need to correct myself.  I forgot about the word separator behavior in FM where 'alpha-dot-alpha' is counted as one word.  There are many ways to get the extension from the file name ... here is one:

Let ( 
name = GetContainerAttribute ( yourTable::yourContainer ; "filename" ) 
;
RightValues ( Substitute ( name ; "." ; ¶ ) ; 1 )
)

or to eliminate the trailing return:

Let ( 
name = Substitute ( GetContainerAttribute ( yourTable::yourContainer ; "filename" ) ; "." ; ¶ )
;
GetValue ( name ; ValueCount ( name ) )
)

 

Edited by LaRetta
Link to comment
Share on other sites

 

@LaRetta:  Thanks.  That does work.

But in Windows on my PC, I've found that a simple GetAsText also returns the file's name, just like GetcontainerAttribute.  I haven't tested all file types, but it seems to work for PNGs.

Thanks for the other responses, also.

 

 

Link to comment
Share on other sites

This topic is 3009 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.