E
E
Eugenue Cesarevich2021-06-24 19:14:01
Java
Eugenue Cesarevich, 2021-06-24 19:14:01

How to work with the file system in Spring Boot?

I found some guides about this, but here's what I'm worried about...

First of all, now while I'm working on the project, the files will be saved to my computer. But then, when I upload the project to the server, there is another file system, other directories, etc. - how to deal with it? Plus, my computer is on Win, and the server will most likely be on Linux.

Second, what about security? How do I filter what is being downloaded to me? And then some script will be loaded or something else. How can you track it at all?

How to keep track of remaining disk space?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2021-06-24
@cot_shaurma

But then, when I upload the project to the server, there is another file system, other directories, etc. - how to deal with it?

Well, firstly, as Dmitry Roo 's colleague noted, you need to use relative paths.
Second, you must have multiple configuration files (with different profiles). For example, for dev upload.pathit will be /home/Desktop/uploads, and for prod it will be uploads/, etc.
Second, what about security? How do I filter what is being downloaded to me? And then some script will be loaded or something else. How can you track it at all?

Usually, they do a MIME type check, both on the client side and on the server side.
For example, using js, you can disable the loading of other files, except for image/*etc.
I do the same on the server. They check the format of the uploaded file and if it does not match the expected MIME type, then throw an exception and delete the file.
How to keep track of remaining disk space?

See what is meant in this case. If hosting, then java.nio will do. And if it's amazon s3 or another service, then see the REST API documentation.

D
Dmitry Roo, 2021-06-24
@xez

But then, when I upload the project to the server, there is another file system, other directories, etc.

To do this, they came up with relative paths, configuration files, symlinks, etc...
what about security?
prevent the user from downloading anything. What the user uploaded - never run.
How to keep track of remaining disk space?

Java io
Java nio

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question