开发者

how to avoid the naming conflict b/w uploaded files

A web application uploads files (images only) from client to server location no any DB and also save the same file/files from server to client's machine.

Process 1. upload a file <input type="file /">

2. save files into server predifined location : java

3. download the same files from server to client's machine by开发者_开发技巧 clicking on save button

problem : let suppose there are two users and they are uploading different files with same name at same time in predifined (or programmed) server's folder.

then how should i avoid this kind of naming conflict & how to programmed for, which file belongs to whom (client) .

possible sol'n : during uploading the file from client to server, create one folder for each client and save the file into specifiec newly created folder.

please note that there is no any Database in application. please suggest any better

Environment : java servlet Apache-tomcat 6.0 xhtml


Use HttpServletReqeust.getSession() method to get client's unique session and then HttpSession.getId() to get session's identifier which you can use in directory/file name construction.


create one folder for each client/user.

Seems like the obvious solution to me. Using session id will result in many more directories being created. If the server saved images are to be used later(which I assume they are, otherwise whats the point of saving them). Having a directory structure based on usernames(or similar) would be much less painful to navigate than anything else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜