Using NodeJS and a local server for development, I’m trying to upload a pdf document to a directory created in “/public” folder.
In the settings I set up links relative to the Site Root:
When I try to open the file using the stored path in the database the file cannot be found (404). It can be found using the path without the “public” directory prefix on the beginning of the stored path.
So you just need the /public removed from the database insert? or removed from the link once its posted? Either way you should be able to use a formatter to remove the ‘/public’ part of the URL.
I just have to remove the /public from the database insert. Of course it is doable with the formatter but this should not be stored in the database in such a way.
Relative to the site root defines how path shoud be returned - i think this is the issue.
The other thing is that url from the file upload action returns NULL.
It’s due to the way that node servers work and the fact that Wappler has to cater for multiple server technologies
Your upload path is correct /public/faktury
This is required as the path to the directory
HOWEVER node treats the /public folder as the site route so the path to the file is not the same
if the file is called “myimage.jpg” the the path to the file with reference to the browser is simply: /faktury/myimage.jpg
Best practice is to only store the filename in your database
Then when displaying the image in app connect append the path to the image
So your image link will be /faktury/{{imagename}}
like this:
Obviously substitute “imagename” with the name of your database field
Sorry, missed you are using a pdf, not an image, technique is identical
Brian explains the reasons behind this very well. I handle it a bit differently though (not better, just different).
In my database I have a typical varchar to store the entire path to the file. I use this when I need to delete the actual file, or load it for processing on the server etc.
I then add a second generated column that is simply a pointer to the original file path, but removes /public/ from the string.
When doing a query to retrieve the path needed from an img tag, or background, I use the generated column instead of the physical file path.
The main reason for this approach is that I only have to set this up once and never have to think about the path again. Saves me from making typos.
If use direct File Upload Action the value on database should be {{upload.url}} and not path.
Now if use Resize, Load Image and Save process I do this to solved:
Use whatever best suits your needs
I tend to use the custom paths in html and image name only in DB as i tend to store multiple copies of images at different sizes into separate folders so i can use optimised images where appropriate.
For example i will have
/foldername/raw (image as uploaded, unchanged)
/foldername/large (perhaps 1280 or 1024 wide)
/foldername/mid (perhaps around 640 wide)
/ffoldername/raw (perhaps around 160 wide
so depending on which image i want to display, my path will be different for example
a main image may be /foldername/large/myimage,jpg
but a list view may only need a thumbnail
/foldername/thumb/myimage,jpg
If i need to store full paths then i would have to store the full paths 4 times
Use whatever best suits your specific needs, it’s down to preference and use case