Ask Your Question
0

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

asked 2019-12-13 07:36:20 +0200

stabiloboss gravatar image

updated 2019-12-13 14:15:33 +0200

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!

edit retag flag offensive close merge delete

Comments

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.'

Pansmanser gravatar imagePansmanser ( 2019-12-13 11:52:44 +0200 )edit

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

stabiloboss gravatar imagestabiloboss ( 2019-12-13 13:35:39 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2019-12-13 19:44:45 +0200

Ratslinger gravatar image

updated 2019-12-13 22:35:37 +0200

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.

edit flag offensive delete link more

Comments

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

Ratslinger gravatar imageRatslinger ( 2019-12-13 20:12:07 +0200 )edit

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.

stabiloboss gravatar imagestabiloboss ( 2019-12-15 09:30:20 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2019-12-15 21:14:57 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-12-13 07:36:20 +0200

Seen: 100 times

Last updated: Dec 13 '19