I want to make a system where java client programs send images to a central server. The central server saves them and runs a website that uses these images.
How should I send the images and how should I receive them? Can I use the same webserver for receiving and displaying the website?
You need 3 things:
Upload client Need to know how to do multipart upload. See here
Upload Server There are a couple of ways. Apache Commons Upload is my pet.
Displaying File It's easy. If the files are uploaded somewhere under your web-app directory outside of WEB-INF directory. Just give the path like http://your/apps/base/url/folderName and the listing will come-up for download. There are ways to secure that. But I donot think you need to know that at this stage. By the way this may help.
And yes, same server can be used to upload and display (download) the images/files.
Hope this helps.
Related
I have logs in folder /home/a/b (located in a remote server)
I want to display logs in my web browser using Java. To get data in the folder /home/a/b and to display them on my web page, what are some methods(API) I can use?
The simplest approach I can imagine is using a SSH API like JSch,
but I don't know how performatic this is.
Anyway, here goes a good example:
https://stackoverflow.com/a/9019095/7528396
Note that you can read the remote file and render line by line.
I am new to GWT, I am facing some issue with file creation.
I am uploading a file from client side and want to store that file
in server side and parse it and create tables in database for the data
present in the file.
When I try to create a file at server side there is some file.io permission issue
App engine is not allowing me to create the file.
Please let me know how can I solve this issue.
I did browse net, didn't find any solutions.
Thanks in Advance,
Pradeep
You cannot store files to GAE as you do normally on a Web Server because you have no direct access to the file system. GAE gives you other ways to that using services.
There are two ways to store files on GAE :
BlobStore
Google Cloud Storage
I suggest to give a try to gwtupload, it has a servlet and a set of FileItemFactory to store uploaded files in BlobStore, FileApi and MemCache.
suppose in my web app user click on download button so a file downloaded into his system. So can i get that client's download location like where the recent downloaded file present in my client system
You cannot get this information.
It is sandboxed, the server will not be informed by the client about the location.
This is not possible since you don't have access to user's file system through the browser (JavaScript).
Maybe using a module or whatever directly in the browser.
You don't. All you get is the file name...
What woule it help you anyway as your server does not have the same structure.
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" />
Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading operation of the file.
Thanks.
That's not possible. The client needs to send (upload) the file content along the request body to the server side whenever you want to have the file content at the server side.
If you'd expect that you can solve this by passing only the file path around and use the usual java.io.File stuff and so on, then you're on the wrong track. Imagine that I am the client and I have a c:/passwords.txt, how would you as being the server at the other end of the network ever get its content by java.io.File?
I don't thnik this is possible. Browsers do not allow any file transfer from the client to the server without user interaction.
Tough, if you do not stick to IceFaces, it may be possible to achieve this by writing an applet, wich is granted the necessary permissions.