1. Create a Record. Create a record to hold the images you want to schedule for display. In this example, I have chosen a field (FILE_DATA_JPG) that will only hold J-PEG images. Build the record so that it exists in the database.
2. Create a Page. Create a component and page on which to use your new record. The page will look something like this. The white box on your App Designer page is an image object that will display the image that you select from your file system.
The image box on the associated web page will stretch to fit the size of the image that you select from the file system. At a minimum, place an edit box on your page that is assigned to the IMAGE_NAME field of your record (you can make it invisible if you want). Otherwise, clicking the Add Image button will do nothing (actually if you call Messagebox on the return code from your call to InsertImage, you'll see that it's returning a 1).
Attach the component to a menu of your choice. Set up the
security that you need to get to the new component and create the appropriate
navigation to your page.
3. Add Some PeopleCode. On the Record PeopleCode behind the Add Image button type in this PeopleCode:
&rc
= InsertImage(Y_MFC_IMG.FILE_DATA_JPG);
Here's where it gets easier than I thought. The InsertImage function is smart enough to call your operating system's File
Attachment dialog and, once you have selected an image, to validate and place
the image into the record column suited to handle an image file, as partially illustrated below:
I haven't experimented with adding two FILE_DATA image fields to the same record, but I suppose it would be problematic to do so.
Using my example, because the FILE_DATA_JPG field
will only hold J-PEG files, you will see an error similar to the following if
you try to insert any other kind of image into it:
Somewhere in the SavePreChange PeopleCode of your record created in step 1, provide for the
populating of the DateTime Created and Updated UserID fields by typing in this:
Y_MFC_IMG.DATETIME_CREATED
= %Datetime;
Y_MFC_IMG.UPDATED_USERID
= %OperatorId;
4. Navigate to the Page and Add an Image. Once you’ve navigated to your page and added an image, your
page will look something like this:
After you are done adding the image, don't forget to click the Save button on the page in order to save the record to the database.
Here's an example of a large image that I inserted.
Let me know what I might have missed, or if you have any questions.
5 comments:
Frank,
Thanks for the example! This worked perfectly for what I needed to do.
Bruce
Very useful example, thanks!
Do you know how to do the reverse?
Retrieve the image from the database and display it on the page?
Thanks for the example.
I'll leave this useful tip.
In case you want to update the image, you have to add the field PSIMAGEVER in the record.
Thanks.
Can we allow different image formats options for users to upload the image instead of 1 like jpeg,bmp,pdf.
Post a Comment