Base - how to set image control to save url as relative or absolute path

Hi,
I have a form with image controls. I can populate these image controls at runtime by right-clicking them, which pops up a menu to insert an image (and remove an image if there is already an image. ). I do not want to save the images themselves in the database, I only want to save their url’s. When I insert an image, the image control writes the url of the image to the table. Currently, my images are stored in a subdirectory of the database, and the url’s are written as a relative path (relative to the location of the database). This however breaks other functionalities like passing the url to an external image viewer. This requires the absolute path. How can I force base to write the url’s as absolute paths? In other instances, the relative path might be preferable, so idealy I hope to find a switch to determine whether url’s are saved as relative or absolute paths.

Using LO 6.2.8.2 on Linux Mint 18.3 mate
tnx!

I’m not sure I understand what you are doing here. I take it that you are editing a form and inserting an image control. But right click on the resulting box does not offer ‘add image.’

Sorry for the confusion, I was talking about the form at run-time, not design-time. I edited my question to clarify.

Hello,

This, based upon a previous question, is because of wanting to see images using a viewer. As stated this could also apply to other situations but will continue with the viewer scenario. With Ubuntu Mate this viewer is “Eye of Mate” and is executed with “eom” used in the code below.

Instead of modifying the stored relative location, it is better to leave as is for sake of transporting to a different location or computer. So the next step is to obtain the missing information. This is available with ThisComponent.geURL() and a function from the Tools library.

First retrieve your relative URL. Then insure the library is loaded. Add the line of code to retrieve the URL and extract its’ directory and also append the relative URL to it. The result is used as the absolute path for the viewer:

sRelativePath = YOUR_EXTRACTION
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
      GlobalScope.BasicLibraries.LoadLibrary("Tools")
   End If
sAbsolutePath = DirectoryNameoutofPath(ThisComponent.Parent.getURL(), "/") & "/" & sRelativePath
Shell ("bash -c 'eom " & sAbsolutePath & "'")

This is based upon your use of Linux and would require modification for use on a different OS.

Edit:

Forgot to test using form. Was testing from IDE and from form need to get Parent. Above code corrected and tested from form with execution using push button.

Please note that the term “sRelativePath” is actually the relative path and file name.

Thanks, Ratslinger. Yes, your solution was the workaround that I had come up with, but your code snippet was new for me, and very handy, so thanks. I do get your point about the advantages of relative paths. At the same time I find it somewhat unexpected that you cannot just pass on url’s between ImageControls, because the first ImageControl will retrieve a relative url, while the second one requires an absolute url. Seems… strange.

It, for what I see, is not passing between controls. One is an image control in a form. The other is a program in Linux.