简体   繁体   English

如何在Java EE Web应用程序的MYSQL中存储文件的物理文件位置?

[英]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. 我在eclipse中为云Web应用程序提供了三个项目,用户可以在其中登录并且应该能够存储文件。

Front end (servlets/html/jsp), 前端 (servlets / html / jsp),

Middleware (ejb's), 中间件 (ejb),

Backend (MYSQL server) 后端 (MYSQL服务器)

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. 据我了解,不建议使用BLOB,而是应该存储物理文件位置。 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. 在Web应用程序中,用户目录与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. 您需要一个共享表,该文件将文件ID与用户ID或组ID链接在一起。

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. 如果您使用了如上所述的哈希名称,那么其他人将无法猜到文件名+您可以避免编写冗长的代码来将文件从云中获取到servlet容器并将其内容传递给用户的麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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