简体   繁体   中英

How to store physical file location of files in MYSQL for a java EE web application?

I have three projects in eclipse for a cloud web application where the user can login and should be able to store files.

Front end (servlets/html/jsp),

Middleware (ejb's),

Backend (MYSQL server)

There is already a working login form connected to the database that authenticates users.

From my understanding, BLOB is not advised and i should be storing the physical file location instead. I need to store the following information about each file:

  • file-name ,
  • file-type ,
  • physical-file-location ,
  • webcloud-location

Ideally the user should be able to have access to other users directories if given permission.

So is that achieved in the same manner as implementing a login table that holds user credentials?

How exactly can a user download a file if the database only stores the location of the file?

Where to store.

You are indeed correct that it's advisable to store merely the file location in the database instead of the file itself. The usual practice is to use a unique hashed name when storing the file in the cloud while saving both the unique hash and the original file name in the database.

Sharing

In web applications, user directories aren't the same as user directories on linux. In a web app, they are virtual. What you need is a sharing table that links file ids with user id or group ids.

How to download

This is simply a matter of giving a link to the file as stored on the web cloud. If you have used a hashed name as mentioned above the file name is not guessable by others + you avoid the hassle of writing long lines of code to fetch the file from the cloud to the servlet container and pass through it's content to the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM