Storing Binary data

5 messages Options
Embed this post
Permalink
David Alter

Storing Binary data

Reply Threaded More More options
Print post
Permalink
I have written a FMP plugin. One of the things I now need it to do is  
store Binary data into a container field. I have been able to get this  
to work with JPEG files but none of the other supported formats.

Even with JPEG I'm not getting the results I would expect. I get an  
icon in the container field showing that it has some kind of image,  
but I do not get the image showing up in the container field. Before I  
was calling AddSIZEData I was not even getting the icon. If I export  
the content of the field it creates a file with the correct image. I  
have been unable to find any sample code for dealing with binary data.

Could someone help me understand what I'm doing wrong. Here is the  
code....


   fmx::BinaryDataAutoPtr resultBinary;
   std::string result;

        //Fill results with some binary data

   const fmx::QuadCharAutoPtr data_type('J', 'P', 'E', 'G');
   resultBinary->AddSIZEData(100, 100);
   resultBinary->Add(*data_type, (unsigned long) result.length(),  
(void *)result.data());
   results.SetBinaryData( *resultBinary);


thanks for the help
-dave

Jake Traynham

Re: Storing Binary data

Reply Threaded More More options
Print post
Permalink
Hi David,

   All my code predates the AddSIZEData and AddFNAMData functions, so
I'm just guessing here, but you might need to use AddFNAMData to add a
filename for the image.  Although now that I think about it, it seems
like I was adding images into container fields without specifying
filenames before I knew how to specify a filename.

   How about this, create a database with just a container field, use
your plug-in to put one of your jpegs in it, and then send the db
directly to me at my email address and I'll take a look at the container
to see if I see anything odd.  Also, are you creating a jpeg from
scratch within your plug-in, or are you loading one from a file?  If you
are loading one from a file, send me the original image too.

Jake

David Alter wrote:

>
>
> I have written a FMP plugin. One of the things I now need it to do is
> store Binary data into a container field. I have been able to get this
> to work with JPEG files but none of the other supported formats.
>
> Even with JPEG I'm not getting the results I would expect. I get an
> icon in the container field showing that it has some kind of image,
> but I do not get the image showing up in the container field. Before I
> was calling AddSIZEData I was not even getting the icon. If I export
> the content of the field it creates a file with the correct image. I
> have been unable to find any sample code for dealing with binary data.
>
> Could someone help me understand what I'm doing wrong. Here is the
> code....
>
> fmx::BinaryDataAutoPtr resultBinary;
> std::string result;
>
> //Fill results with some binary data
>
> const fmx::QuadCharAutoPtr data_type('J', 'P', 'E', 'G');
> resultBinary->AddSIZEData(100, 100);
> resultBinary->Add(*data_type, (unsigned long) result.length(),
> (void *)result.data());
> results.SetBinaryData( *resultBinary);
>
> thanks for the help
> -dave
>
>

--
Jake Traynham
Owner, CNS Plug-ins
http://www.cnsplug-ins.com/
nexes300

Re: Storing Binary data

Reply Threaded More More options
Print post
Permalink
Hello,

About this issue, I have gotten JPEGs to display within filemaker from a container field,
however PNG only shows up as an icon still. From what I've read in the comments in the
binary data header file, it appears that a JPEG stream is required for all pictures. Is this
true, and if so is this because the JPEG stream is used as a preview?

If it is not true, then how do I properly construct the binary so that it displays correctly in
Filemaker when returned by the plugin function?

Also, why is the SIZE stream required? Is there a way to have filemaker automatically
determine the correct sizing? Or will I have to use another image library to determine the
correct size?

Sorry for having so many questions but there isn't very much documentation about this.
Any help would be appreciated.

Thanks!

Charles

--- In [hidden email], Jake Traynham <jake@...> wrote:

>
> Hi David,
>
>    All my code predates the AddSIZEData and AddFNAMData functions, so
> I'm just guessing here, but you might need to use AddFNAMData to add a
> filename for the image.  Although now that I think about it, it seems
> like I was adding images into container fields without specifying
> filenames before I knew how to specify a filename.
>
>    How about this, create a database with just a container field, use
> your plug-in to put one of your jpegs in it, and then send the db
> directly to me at my email address and I'll take a look at the container
> to see if I see anything odd.  Also, are you creating a jpeg from
> scratch within your plug-in, or are you loading one from a file?  If you
> are loading one from a file, send me the original image too.
>
> Jake
>
> David Alter wrote:
> >
> >
> > I have written a FMP plugin. One of the things I now need it to do is
> > store Binary data into a container field. I have been able to get this
> > to work with JPEG files but none of the other supported formats.
> >
> > Even with JPEG I'm not getting the results I would expect. I get an
> > icon in the container field showing that it has some kind of image,
> > but I do not get the image showing up in the container field. Before I
> > was calling AddSIZEData I was not even getting the icon. If I export
> > the content of the field it creates a file with the correct image. I
> > have been unable to find any sample code for dealing with binary data.
> >
> > Could someone help me understand what I'm doing wrong. Here is the
> > code....
> >
> > fmx::BinaryDataAutoPtr resultBinary;
> > std::string result;
> >
> > //Fill results with some binary data
> >
> > const fmx::QuadCharAutoPtr data_type('J', 'P', 'E', 'G');
> > resultBinary->AddSIZEData(100, 100);
> > resultBinary->Add(*data_type, (unsigned long) result.length(),
> > (void *)result.data());
> > results.SetBinaryData( *resultBinary);
> >
> > thanks for the help
> > -dave
> >
> >
>
> --
> Jake Traynham
> Owner, CNS Plug-ins
> http://www.cnsplug-ins.com/
>


Jake Traynham

Re: Re: Storing Binary data

Reply Threaded More More options
Print post
Permalink
Hello again,

nexes300 wrote:
>
>
> Hello,
>
> About this issue, I have gotten JPEGs to display within filemaker from a
> container field,

Good to hear you got it working.  What was the issue, if you don't mind
me asking?

> however PNG only shows up as an icon still. From what I've read in the
> comments in the
> binary data header file, it appears that a JPEG stream is required for
> all pictures. Is this
> true, and if so is this because the JPEG stream is used as a preview?

The JPEG stream is used as the preview image for all image formats that
filemaker can't natively display.  Filemaker tells you that it can
display JPEG and GIF images natively and that everything else has to
have a JPEG version of it created in order to be displayed.  However, it
will display PNGs (and some other image formats I believe) if you insert
an empty JPEG stream.  (ie. MyBinaryData->Add(*fmx::QuadCharAutoPtr('J',
'P', 'E', 'G'), 0, NULL); )

Another thing to note is that, for some reason, Instant Web Publishing
will only display the JPEG preview and will never show the PNG.  (In my
testing anyway .. if someone knows how to make Instant Web Publishing
display a PNG, please let me know.)

>
> If it is not true, then how do I properly construct the binary so that
> it displays correctly in
> Filemaker when returned by the plugin function?
>
> Also, why is the SIZE stream required? Is there a way to have filemaker
> automatically
> determine the correct sizing? Or will I have to use another image
> library to determine the
> correct size?

Unfortunately, it is required.  It would be nice if FileMaker at least
provided a function for generating the SIZE stream from an image (seeing
how their own code does it if you "Insert" a picture from the UI) but
for now you will need to determine the size yourself.  It's possible to
write some quick and dirty code to extract those values yourself out of
at least gif and jpeg images.  (For example, the GIF width and height
are WORD values at 6 and 8 bytes in from the beginning of the file.)  Of
course, if you are generating these images yourself, you should know how
big they are.

>
> Sorry for having so many questions but there isn't very much
> documentation about this.
> Any help would be appreciated.
>
> Thanks!
>
> Charles
>

I hope this helps,
Jake

--
Jake Traynham
Owner, CNS Plug-ins
http://www.cnsplug-ins.com/
nexes300

Re: Storing Binary data

Reply Threaded More More options
Print post
Permalink
Thanks! That was actually very helpful.

The problem was with this line: resultBinary->Add(*data_type, (unsigned long)
result.length(), (void *)result.data());

result is a std::string, and before I was using result.str() which cuts off after a null byte.
Then when I did switch it to .data() I think the problem was that my picture wasn't really a
jpeg. Go figure.

Anyways, thanks for the quick response.

Charles

--- In [hidden email], Jake Traynham <jake@...> wrote:

>
> Hello again,
>
> nexes300 wrote:
> >
> >
> > Hello,
> >
> > About this issue, I have gotten JPEGs to display within filemaker from a
> > container field,
>
> Good to hear you got it working.  What was the issue, if you don't mind
> me asking?
>
> > however PNG only shows up as an icon still. From what I've read in the
> > comments in the
> > binary data header file, it appears that a JPEG stream is required for
> > all pictures. Is this
> > true, and if so is this because the JPEG stream is used as a preview?
>
> The JPEG stream is used as the preview image for all image formats that
> filemaker can't natively display.  Filemaker tells you that it can
> display JPEG and GIF images natively and that everything else has to
> have a JPEG version of it created in order to be displayed.  However, it
> will display PNGs (and some other image formats I believe) if you insert
> an empty JPEG stream.  (ie. MyBinaryData->Add(*fmx::QuadCharAutoPtr('J',
> 'P', 'E', 'G'), 0, NULL); )
>
> Another thing to note is that, for some reason, Instant Web Publishing
> will only display the JPEG preview and will never show the PNG.  (In my
> testing anyway .. if someone knows how to make Instant Web Publishing
> display a PNG, please let me know.)
>
> >
> > If it is not true, then how do I properly construct the binary so that
> > it displays correctly in
> > Filemaker when returned by the plugin function?
> >
> > Also, why is the SIZE stream required? Is there a way to have filemaker
> > automatically
> > determine the correct sizing? Or will I have to use another image
> > library to determine the
> > correct size?
>
> Unfortunately, it is required.  It would be nice if FileMaker at least
> provided a function for generating the SIZE stream from an image (seeing
> how their own code does it if you "Insert" a picture from the UI) but
> for now you will need to determine the size yourself.  It's possible to
> write some quick and dirty code to extract those values yourself out of
> at least gif and jpeg images.  (For example, the GIF width and height
> are WORD values at 6 and 8 bytes in from the beginning of the file.)  Of
> course, if you are generating these images yourself, you should know how
> big they are.
>
> >
> > Sorry for having so many questions but there isn't very much
> > documentation about this.
> > Any help would be appreciated.
> >
> > Thanks!
> >
> > Charles
> >
>
> I hope this helps,
> Jake
>
> --
> Jake Traynham
> Owner, CNS Plug-ins
> http://www.cnsplug-ins.com/
>