I have been trying many days to get the image to be inserted into a path that I specified in the application.properties but to no avail.
And I am not sure where I had done wrongly such that when I printed out the path it would not include the the last / and so the image will not get into the folder but append to the last part of the path and not after the /
Here's the applicaiton.properties:
To be more clear,
my path is C:\User\abc\foldername\
So for the calss FileStorageProperties it will give me the exact path as put in the application.properties
but when I print out the controller it will just print C:\User\abc\foldername and the image name will append right after foldername
I am exhausted and I am beaten.
I am not sure what to do now and it is like nobody can help me cos everyone said all the answers are in the internet but really I have tried so hard I still can't get it right.
Rob Spoor wrote:It could be caused by the properties parsing that uses \ as an escape character.
It the only issue is that the directory is missing a trailing \, then the solution is actually quite simple. Don't use string concatenation, use Path.resolve:
I'd like to know if this code is used in the cloud ... I mean if the app is being hosted on the cloud and say if I changed the C:\ blah blah blah to a location in the db in the cloud, will it work or I need to take note of further configuration and the API being used.
With the resolve method, it will resolve the file relative to the path. Windows supports both \ and / for directory separators, Linux only /. As long as you don't have any \ in the path to resolve, the method should do the same on both Windows and Linux.