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.
Related
Ok, I'm a beginner so this maybe stupid but i afraid that clients can modify static resources (css/javascript files) on server if they can load them directly through URL path (Of course I have to put css/javascript files outside of WEB-INF folder).
If my hypothesis is wrong, could you give me links or quotes to help me expand my knowledge ? Thank you :)
When a user's browser requests resources from your server, they are performing a GET request. This request will not directly change any file on your server. The request will go through your web server and will be processed. In the case of the resources such as css/javascript files, the web server sees the user is requesting the file and sends the contents of the file back. There is no way the user can update the contents of those files on the server unless you write code on the server to allow them to update the files. If the user has direct access to the server via ssh or other protocol and has permissions on the folder that holds the resources, they would be able to change them.
The whole process is much more complex for going through the web server, but for brevity left out here. Here is a good article that explains what really happens when you go to an address in a browser:
https://medium.com/#maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a
I have a web application running on Weblogic 12c using Java7 as backend and angularjs in front end.
I want to be able to download/upload one (pdf) file from it.
The basic user cases are :
The user can click on a button to download the file.
The user can click a button and pick a local file, this file will then be uploaded and replace the previous one as the downloable file.
There will only be one file.
I've tried to find a solution online and I ended up creating a File Store (with a direct-write policy).
But I haven't found how to download the file when using my application.
Also, I'm not sure this solution will work for my upload case.
How can I et up my application to download/upload this file ?
Filestores are a wholly different concept, used to store JMS messages. Don't let the name confuse you, this is not a usecase for filestores.
Consider this Q for handling the file upload: How to upload files to server using JSP/Servlet? - and save the file on a folder in the filesystem. Your WebLogic 12c installation supports servlet 3.0 annotations.
Can any one help me on the following issue. I have index.html file in that
<td><input type="file" id="testsuitepath1" value="testpath"></td>
By using the above line I am able to browse files from my local system path instead of server path. So ,in Servlets is there any way to access the files by clicking on browse button in the server location.
No, not by default. A web server, at least in part, does what you want - it serves files from the server side. But by default it doesn't let you just browse any file nor see all of the files on the server side. You could write a servlet to do this but you need to be careful to not all the client to access sensitive files.
The .html works at client side. That's why you are able to browse files from local system.
A servlet is delpoyed at server side , So a servlet can access files/resources stored in the web-app that is deployed on that server. This is called accessing relative resources.
Moreover, If you want to access the files from the server via browse button then, you should have the access to the network location where the web-app is deployed.
Later, in the filename(browse window) you can search the path of the server.
e.g: \\web-app\file1.jpg
Personally. I think you have a bad software design issue.
I develop a web application using JDeveloper. Then, my scenario is I want to get a file from client directory (e.g. C://Image.jpg). What I want to achieve is the client's directory defined programmatically. So, I used InputStream, but it will search a file in server directory. if I used UploadedFile, I don't know how to define it. Note that I don't want to use InputFile.
Does anyone have a solution for me?
Search for HTTP File Upload. You need an <input type='file'> control on your webpage, and form encoding set as enctype='multipart/form-data'.
Generally, you can't control the default directory where the browser is going to open a file chooser -- it normally starts from the "user home" directory, but other dirs can be navigated to.
i have a web application which stores users file in directory which is under webroot directory..
Suppose web application is under 'fileupload' and all files are getting stored in 'xyz' folder under 'fileupload' so now if user points to url say like
www.xyzpqr.com/fileupload/xyz/abc.doc, he gets that file.
How do i restirct this from happening.. i have thought of putting xyz folder in WeB-inf folder but as my application is very big i have to made changes at too many places.. so is there any way so that without moving the folder to web-inf (restricted folders) i can achieve wat i want..
In many cases, this is something that you can set in the configuration for the webserver your files are stored on. You can require passwords for directory access, or restrict things even further than that. It will vary by implementation exactly what configuration file you need to look at, but some common ones are http.conf and .htaccess
If you're unsure, it's probably worth it to contact your hosting company and/or network admin.
Hi if you are using Apache web server you can protect a directory by password. But you need to be able to edit/create .htaccess file.
Here's the solution for WAMP server:
http://php-mysql.develop.sitefrost.com/PHP/security.php
It is very similar for other platforms. When someone wants to access a protected directory he must first submit username and password.
I would suggest creating a filter which examines every URL to see if the user has access to that particular file and denies the request if not.
This gives you full control.