Code Example of How to Attach a Photo to a Record

could someone please show me where to find a Code Example of How to Attach a Photo to a Record?
Thanks ~Jack

1 Like

Here is the Panorama X documentation about Image Display Objects.

Basically you donā€™t save images in the database, you save paths to images in your database. It is comfortable to keep those images in (a subfolder of) the folder of your database, because then you can use simple relative paths.

1 Like

I have a database which lists tools which I own. What I want to do is:

  1. Use have an input form where I enter the item description.
  2. Drag a jpg picture of it to a place on the form where it is programatically attached to the record.
    Utter simplicity but I donā€™t know how to do it.

Thanks for the Pan X object/image page which you referred. I spent over 2 hours searching for something like that.

Unfortunately there is no documentation on this topic at this time.

I think this would work:
You must have one or more database fields already, holding information on the tools. Add a field to hold the path to its jpg. On the form add a text editor object linked to that field. And an image display object set to display the current record of that field. You can set that with a ā€˜defaultā€™ imaging pointing to a generic picture saying ā€˜image neededā€™ or some such. Then, with the toolā€™s record showing, just drag and drop the image file into the text editor object. In principle that should put its path into the linked record field. May need some tweaking, but Iā€™d suspect Help on TEOs and IDOs would get you by.

Create a text field named Images on your data sheet. On your form create a Drag Receiver Object the size of the image you want displayed with the path added to your Images field. In the Options panel set the Accepts: option to Files and the Extensions: to .jpg.png with no quotes or spaces between the extension names. In the Procedure panel of the Drag Receiver place this code: Image=catcherror("",info(ā€œdropfilesā€)).

Create an Image Display Object on top of the Drag Receiver and set it to the same size as the Drag Receiver. Set the Formula pane for this to simply Images. Now if you drag a file from the Finder onto the combination Image Display/Drag Receiver it will display the image at the same time as it is putting the image path into the Images field of the current record. The related image will now show for each record as you navigate through them.

DragImage

2 Likes

Drag Receiver Object, not yet documented by Jim nor noticed by me in the Object Library. Sounds better than my text editor suggestion. Perhaps itā€™s in the latest videos Iā€™ve not yet found time (but will!) to watch.

Nope, as I mentioned earlier itā€™s not documented anywhere I donā€™t think. But Gary has described it accurately. Maybe I privately explained it to him at some point, or he may have reverse engineered it from a database I posted.

The drag receiver object will continue to work, but I do have some ideas for possibly enabling drops on other types of objects, which is one reason this isnā€™t documented yet.

I do have to question Garyā€™s taste in example images though!

No, this one was easy to figure out with the objectā€™s name and the items in the Options panel. The hardest part was finding out the exact syntax for adding the extensions filter. I was given a clue, however, with the description of File Types in the dropfromfinder documentation. I have been using this method for some time now including in a few place on my current project.

You might be remembering a discussion we had way back when regarding the undocumented Elastic Zone object. I couldnā€™t figure out what it was for or how to use it and you told me it wasnā€™t fully implemented and may never be completed. I was getting all kinds of weird actions when experimenting with it.

1 Like

Gary has provided a perfect answer to the question how to attach a picture to a database record, but this is not the best method to attach a folder with a lot of pictures to a database.

Suppose your database has one field ā€œPathā€.

Panorama X can list the files contained in a folder (see the documentation of the filecatalog( function) and append the array of the found file paths to your database (see fileappend or importtext documentation. Then you only need a form with an Image Display object with the formula

Path

to display the images for all records.

1 Like

I want images associated with their own records ONLY. Might be multiple images per record but not multiple records per image. Simple minded example is a names list with an attached photo for each name.
Jack

Thanks Gary,
I will try, and let you know the result, when I have time.
Too bad it takes so much programming. I think this should be built as a feature object because it is so commonly used. Flexibility at all costs is not always good. It can be a pain to use. This ia IMHO.
Jack

I did not talk about multiple pictures per record.

I talked about a folder with letā€™s say 100 pictures, associated one by one to 100 records in your database.

Can I just point out that Garyā€™s suggestion involved ONE line of code?

Image=catcherror("",info(ā€œdropfilesā€))

Image=catcherror(ā€œā€,info(ā€œdropfilesā€))

A small but significant detail: I could not get this to work until I changed ā€œImageā€ in the above code to ā€œImagesā€. I presume ā€œImagesā€ matches the Images text field name prescribed earlier in the post. (Iā€™m really inexperienced in writing code for PanX so maybe itā€™s my fault in the way I implemented it.)

I notice the absolute path file is getting filled in to the ā€œImagesā€ text field. Is it possible to have the relative path fill the field?

You could use

Images=catcherror("",after(info(ā€œdropfilesā€),dbfolder()+"/"))

That would clip off everything up to and including the folder containing the database. If the database folder isnā€™t actually in the path, it would just return a blank.

Hmmā€¦Thanks for the suggestion. I put the code in the procedure pane of the Drag Receiver object. Now no text is filling the Images text field when I drag an image onto the Image Display/Drag Receiver combo object in the form.

Is the image file in the database folder, or a sub folder of the database folder? Thatā€™s the only case where my formula should work.

The image file is in a sub folder of the database folder.