Unable to access file in hard drive using Apache Tomcat server - java

I'm developing local-only JSP application using Apache Tomcat server. I would like to put a promotion videos on my intro page, but I don't want to move them to webapp folder or anywhere else.
The promotion videos are located:
E:\data\videos\2018...
But writing a JSP/HTML like this wont launch the video, but however it works off-server (launching html from desktop for example, so the path may not be issue?)
<video src="file:///E:/data/videos/2018/promotion1.mp4" controls></video>

Local file links from remote resources are disabled by almost all browsers by default. There are certain possibilities to overcome that, e.g.:
http://kb.mozillazine.org/Links_to_local_pages_do_not_work
https://discourse.mozilla.org/t/opening-links-to-local-files-file/16449/2
To access your static media files from remote page you need to configure your Tomcat server as described here: http://teknosrc.com/access-local-files-static-content-images-videos-media-files-outside-web-application-system-apache-tomcat-server/

solution:
a.) make sure your server is on the same system where the media files are.
b.) If so, you have to create a folder (ex. media) in your application folder inside /src/main/webapp/ and have to put all media files inside a media folder. After that, you can surely access the media files through a server.

Related

How to browse files in server location using Servlet with input type as file?

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.

SmartGWT *.ds.xml files can be accessed via web browser

I have a Web Maven project that uses SmartGWT. After doing maven install, several *.ds.xml files are created in the install folder under sc/schema subfolder. These files are:
DataSource.ds.xml
DataSourceField.ds.xml
DataSourceStore.ds.xml
DBListDS.ds.xml
DBSchema.ds.xml
JVMClassTreeDS.ds.xml
QuartzJobs.ds.xml
QuartzScheduler.ds.xml
QuartzTriggers.ds.xml
SchemaSet.ds.xml
SimpleType.ds.xml
Validator.ds.xml
WebService.ds.xml
WebServiceOperation.ds.xml
WSDLMessage.ds.xml
WSOperationHeader.ds.xml
XSComplexType.ds.xml
XSElement.ds.xml
They can be accessed via browser at my website link my_site/*.ds.xml, which the browser display a red error message. I have searched around and found nothing related to accessibility via browser of these files.
How do I restrict access to these files? Will the pose any vulnerability issue? Is it safe to let them be?
Thanks
It is perfectly safe to leave those files accessible.
In fact the application may need to access them from the client site to function correctly.

How to get client files in Java bean?

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.

Trigger open&edit file with tomcat WebDav from Java Applet

Currently i have a java applet (with tomcat 6 as backend) that allow users to upload file and download file for document sharing. However, many users forget to upload the edited file back to the server.
Hence, I would like to enhance the applet to allow user to choose a file* for edit and save directly to the web server. Without having the user to save the file to their local harddisk, and upload the file* back to server manually.
After a few goggling, it seems WebDav is the way. I have configure tomcat with the webdav enable in the web.xml, and now i can view file and edit with a Webdav client CyberDuck.
Questions:
is it possible view / edit / lock the file* without installing a webdav client?
Reason is because i have more than 3000 desktop client using the software. Deployment of the webdav is an issue and how do i let each user to access different webdav so they do not see each other's file?
Is it possible to trigger local application to open a file* inside WebDav?
file* = means any file that are able to open from their local machine; examples: ms word, ms excel, ms powerpoint, pdf, PNG, JPG, txt and etc.
Ah, i manage to open it with:
Runtime.getRuntime().exec("winword http://:/xyz/.../pgl_page-bi.doc");
Problem is, every single type of files will need to have a different string inside the .exec(""); not as clean as i expected but at least it works.

How to retrieve images stored in file server?

I have a java web service through which I upload images to a file server. I want to access these images from my java web app. How can I make the image files (and eventually other static files) available from this file server?
The only thing I could think of was to use Apache Http server as a proxy to my web app for these images, but that circumvents the security measures of the web app.
UPDATE:
Servlet container: Tomcat
Web app is on separate server from images.
Web service is on same server as images and has direct access to file system.
Both web app and service use spring security for authentication/authorization, I want to continue to use this security framework to for image access.
How are the files stored?
If security is a concern the best option might be to create a Servlet (or something similar) which will load up the image and serve it to the user, once it has checked their credentials.
How you load the image depends on exactly how they're stored, if you can access them via HTTP you can always open up a URLConnection to the file from the Servlet and serve it directly that way (i.e. using the Servlet as a sort of proxy server).
Without more details it's difficult to be specific.
I'm not sure if this will solve your problem, but it sounds like you should set up a context path that will map a URL to the path on your server. This can be done with tomcat's context files.
For a good explanation of the solution, check out a post on How to Program with Java
Sounds similar to Apache Hadoop.
Once image/file is requested, you have to make API call and pull the file out and do one of the following:
Store the temp file to the "temp" directory on web accessible server. You will need, some kind of cleaner/gc running in the background to clean those temp files. This is how Facebook does it with photos.
Instead of storing file on the server check the file type and set HTTP Content-type header to the appropriate file type. Image source will look like this <img src="getPicture.jsp?id=1234" />

Categories

Resources