most secure way to upload a file from a b4j app
the only thing you can safely do is use HTTPS.
you may try to encrypt the file, but if you are using a predetermined password for that then is useless, there is no feasible way to protect the password, any hacker can read the network, system or any other solution you may come up to.
if you think that the password will be safe within the jar file, that would be completly incorrect. even you use a .so file or a .dll file it would be useless, any person can attach a process in a java machine and hear anything happening on it.
best way is to ask for a user to use their own password, that way you can encrypt on one side and decrypt on the other. dont send the password, you should have it on your server.
Is it safe to be as a file in the directory or is it safer at a db ?
both are unsafe if the server is vunerable, if a hacker have access to the server consider all the info stolen. if the hacker doesnt have access to the server then its the same for both solutions.
but is it real the best way and the most secure ?
yes! just use https!! any other stuff you may come up to is snake oil!
that being said. protect your server. dont disclose your ip (hide it behind a proxy like clouldflare) firewall should always be restricted, anyway to acces the server (sftp, ssh) should have the maximum restrictions possible.