I am trying to find the way of creating an application where I can connect with the users file system and show his own directories in a div, allowing to select files and drop into an HTML5 area.
The main problem is how to get the directory tree, all related to drag and drop HTML5 is solved. The way that I imagine this application, is a div on the left where you can see the tree, and a droppable area on the right, so that user can navigate through his disk and upload files.
Any recommendation, or contribution, or whatever is wellcome. I think that this could be done! It will be hard, but I hope I could solve this!
you DON'T GET access to any directory tree. Security measures
Related
I have a problem about using Struts to download a file. I know Struts is an old technology, but my company is maintaining an old application for a customer.
So, problem is that we want a webpage to download a file. Scheme is the following : Reach for webpage > click a button > execute treatment (DB query and data selection) > produce excel file > download the file > back to initial page.
My code is working until the file download, i.e. I can download a correct excel file, but I can't go back to the original webpage.
I read this answer and others in this forum, and it seems that downloading a file and going back to original page are 2 different treatments, and that Struts can only process one...
I absolutely need those 2 treatments, so my idea is the following : When the user clicks the button on the original page, I should open another window (or even a pop-up) which will take care of the excel treatment and download, and my original page won't move, therefore I don't need to forward at the end of the treatment.
Question is, do you think this is viable ? I couldn't find a similar code here so I guess it isn't a good idea, so if you have a good practice about my need, please share it :)
Yes sure your idea will work. But the user has to close the pop-up after the download starts.
Just to give some other ideas:
I had a similar problem once and solved it a little bit different. Javascript does allow execution of multiple statements in one row with one button (what you would do anyway with the popup and redirect solution).
So you could listen on the click event on the button and download the file and do something different after that.
Here are some topics about downloading files with javascript Link without using a popup. And a simple javascript redirect is also very easy Link #2.
The glue code to struts are two links you have the generate while the user visits your page.
More or less pseudo-code in html/jquery:
<button id="download" data-downloadlink="<s:property value='downloadlink'/>" data-redirectpage="<s:property value='redirectpage'/>">Download</button>
$('#downloadbutton').on('click', function() {
download($('#downloadbutton').data('downloadlink'));
redirect($('#downloadbutton').data('redirectpage'));
});
I'll try to be short with the description of my situation:
I'm making a restaurant recommendation web site. I want users to be able to add a new restaurant and upload 1 picture of the restaurant (restaurant's profile picture). That picture will later be displayed when users search for the restaurants. Each time a new restaurant is added I want to create new folder for that restaurant and place the uploaded picture there.
I can upload an image and place on my file system, but when I try to display it it doesn't show.
<img src="\C:\glassfish4\glassfish\domains\domain1\applications\__internal\WebAppName\profilePicture.jpg" />
This is where I was originally placing the images, but they wouldn't show.
If I understood correctly from here that is not a good practice to reference images in this manner because then the browser will be looking for that location in user's machine.
I tried to place the images in:
C:\glassfish4\glassfish\domains\domain1\eclipseApps\WebAppName
because I figured that this is where WebContent folder is (please, correct me if I am wrong), and that this location is accessible with:
<img src="http://localhost:8080/WebAppName/..."/>
but that worked only for a short time. As soon as I redeployed my app the folders in which the pictures were placed had gone away (and they were created).
So my question(s) are:
How and where to place these images, and what should my src attribute look like in an html document (should it be like C:\... or http://localhost/...)?
What are conventions, practices for this, and how is this generally done?
And does redeployment has anything to do with my pictures being gone?
I found this post, but it did not solve my problem.
Note: - I am using glassfish4, and Java Servlets, JSP, JSTL/EL, and generally Java.
Thanks in advance!
And does redeployment has anything to do with my pictures being gone?
It does. When you redeployed your application, GAS removed the application directory at ${GAS_INST_DIR}\domains\${YOUR_DOMAIN_NAME}\application{YOUR_APP_BUNDLE_NAME}. Once you decided to store you images there, they are gone after the redeployment.
How and where to place these images
The most straightforward way is to put your files somewhere outside application server folder could be a solution but I would say just half a solution. Let's assume you store your pictures in a local folder /var/application/data. Later you decided to cluster your application. Now you are again in trouble. Each instance has its own /var/application/data directory and as a rule you do not know what node will handle a request for storing an image.
What are conventions, practices for this, and how is this generally done?
I would say it is you who decides what way to go according to the needs of your application. I will list the ways that are the most obvious. All have their own strength and weaknesses.
You can put the images in a local folder. The strong side is simplicity. Once you decide to cluster, you would have to remake this approach. If you go this way the most general approach would be to create a servlet that loads your images and in this case your src= will point to the servlet. Did not find a good example right away, but I think this example will give you an idea how to do it. The only thing I would suggest using finally block or if you use jdk 1.7 the try-with-resources for closing stream. Another thing you will need to pass file name as a parameter to the servlet.
Store images in database. It could be RDBMS or noSql. Down side is that not all RDBMSs work efficiently with binary data. Again src could point to a servlet that loads images from the DB. Here you should design your DB accordingly so you can retrieve images effectively. I would not choose this approach, but this is just a personal opinion. Cannot say how efficient the noSql databases are for storing binary data. You should do it yourself
Consider Webdav. In this case your src attribute will be a link to a resource in webdav server. You can use it in clustered environment, relatively simple implementation.
and what should my src attribute
look like in an html document (should it be like C:... or
http://localhost/...)?
Depends on the approach you choose. See item 1-3.
Hope that helps.
To explain my situation, I currently have a large amount of PDFs (In the hundreds). Each PDF has a name associated with it and I need browse an external website my job uses to manage their files manually, clicking a button to "attach file" every time and manually selecting the file to upload to the site. If this sounds incredibly inefficient that's because it is, and doing this takes hours to finish while more of them pile up.
I already know how to deal with files, moving them around on a computer, and modifying them using JAVA, but I haven't done anything related to interacting with websites so I wouldn't know where to start.
I'll need to be able to perform the following actions or actions similar in order to complete what I have in mind.
General browsing of a website
Navigating through the website using
links provided by buttons on the page
Being able to click buttons.
Reading Strings present on the screen in order to compare names (Under a certain section there is a list of peoples names. If I detect that there are multiple people with the same name I want to skip the file and deal with it manually)
Clicking a button which brings up an upload menu and selecting a file to upload to it, or any other way of interacting with a feature such as this. (Like when you click Computer on IMGUR and it asks you to choose an image you would like to upload)
I'm not asking for anyone to straight up give me the answer I'm looking for (Though I'm not opposed if you are aware of how to do things such as these and would like to share.) but any guidance on where to find information on performing such actions would be helpful. I've already been searching and will be continuing to search for relevant information.
Thank you for any help you may be able to give.
It appears you want to automate some manual steps on a browser. You can take a look at Selenium WebDriver.
I am trying to create a program were the user drags a file into an area (currently a JTextArea, but can be another container) and it adds the absolute path of the file to an ArrayList. I am having trouble figuring out how to implement drag and drop of files.
so far I have tried reading some similar questions but they aren't really helping me.
(also this is targeting windows but linux/mac support is an option as well)
Have a look at oracles page about DnD. Basically you can drag everything into your program, should it be a file directly from a native browser or the JFileChooser. What you are dragging is only the path to the file. So you only have to set your JTextAreato accept drops and define how it has to "interpret" the object that was being dropped.
Here is a full blown example.
I am currently coding a program using the language JSP. I was wondering if/how you would restrict the directories a File Open dialogue box can browse, for instance:
The default directory is in C:/userFiles/username/ I want the user to be able to browse files in that /username/ directory, or directories within that directory, but not any directories above like C:/, or C:/userFiles. I have done some research, and I could not come across an answer. Is this possible with JSP, HTML, or Java and if so, how would I do it? I would prefer JSP or HTML.
Additional Info:
The dialogue box would browse files on a remote server, not on the user's computer.
The File Open dialog is on the client machine and is part of the operating system. You cannot change its behaviour.
In order to list files on a SERVER you would not use a File Open dialog, you'd be turning the list of files into HTML and serving that to the browser. Since you're the one writing the server-side code, you are ALREADY the one in control over which files make it into that list in the first place.
Saying you'd prefer "JSP or HTML" is a pretty good indicator that you don't fully understand the client-server relationship of the web.