How to mass upload PDF files and save into MySQL using Servlet? - java

How do I mass upload PDF files or a folder with PDF files and save it into my MySQL database using Servlet?

The best you do is to ask user to specify the files using several <input type="file"...> elements on the page. And on submit check if all the files are PDF or not, perform desired action in either case. Or you can check for the PDF extension right away using JavaScript. You can also validate using AJAX, just send an AJAX request to the server on a onBlur event of the input field.
Otherwise, a privileged applet might be able to help a little more than this. For example asking a directory and scanning for all PDF's etc.

Related

upload a large number of file to java app

I have an application in payara that need to receive thousands of files
I was thinking to manage them using an ftp server to upload the files in a dir created run-time with temporary access.
I was looking to vsftpd, and virtual users, and means that I will need to generate new user by adding them to the users file, using htpasswd format: can someone suggest the best way to do it (I don't like the idea to execute a script on the system called by java).
EDIT
At the moment I'm receiving the files using fileUpload component of primefaces, but it become unusable when more than 1.000 files are selected
That's why I'm not comfortable using any HTML interface
If you're OK with requiring users to use modern browsers, you can use the HTML5 file input attribute multiple, which will open a browser window allowing the user to select multiple files:
<input type="file" name="uploads" multiple>
You can then use Apache's commons FileUpload to parse the HttpServletRequest and extract all the files, then do with them what you want.
This is way easier than setting up an alternative upload mechanism and start syncing it.

Ajax File Upload storing bytes until save java.

I'm a java developer using Tapestry5. I'm using a jQuery plugin to manage my file uploads via ajax.
I'm looking for the best approach to temporarily saving the attachments until the actual page has been saved. My current work flow consist of a user uploading / removing a file with either the ajax upload box or an ajax remove link positioned next to the file like gmail attachments. I do not want to commit the file to the database until after the file has been uploaded and the save action within the form has been clicked.
I'm currently uploading the files and saving them to the user session until the save action within the form has been clicked. This works perfectly fine providing only one tab is in use, however I'm not sure that is the best approach.
Does anybody have any additional suggestions?
I've had to do something somewhat similar, but, with a slightly different stack (ASP.NET MVC).
The way I solved the problem was by generating a GUID on the page load and stuffing it inside of a hidden input. Your data store could be whatever you want (session, database, disk, etc - just be sure to include the GUID as part of your key). When the user saves the form just be sure to include your hidden input data and then you will have a unique way of identifying the files that were part of that instance.
What you are doing so far seems right, and you are also right that you could run into trouble if the user attempts to use your web app within multiple tabs. What you could do is :
Obtain a unique key before any file is uploaded with an ajax call. (note: as user #Ek0nomik suggests, this could also be included in a hidden input property when generating the page)
Whenever a file is uploaded, make sure to also submit this key.
When the form is saved, the key is submitted, you then know which files should be committed in the database.

Preselect files in JUpload

I have a requirement to process an external request to populate a HTML form with the parameters mentioned in the URL. This part is working fine. However, the URL also contains paths to files present on the client machine and I want to upload those files from the client machine to the server without user interaction.
Since it is not possible with HTML/Javascript to programatically select files, I tried using the Applet approach using JUpload. However, I am not able to figure out, how to preselect a file on applet initialization. It is not necessary to upload the files right away, but I want atleast to select the files automatically. User can review the info and then submit the form. and files in the applet.
Is it possible with this library? Or direct me to some better path
OK, so I found my answer in a different library with similar name. With Smartwerkz JUpload we can pass a parameter preselectedFiles="filePath" and autostartUpload=true to preselect files and auto upload files without user interaction. I hope it will help someone someday.

Direct file upload using Ajax or JQuery (with or without a form)

I'm trying to use the second "Direct file upload" method described at the end of the page here: http://www.playframework.org/documentation/2.0/JavaFileUpload
How do I implement the required Ajax/Jquery/Js function that will allow me to use this? Can anyone please provide some hits or snippets?
Thanks.
You cannot upload files using AJAX. At least not in browsers that do not support the HTML5 File API. For those browsers you could use some existing file upload control such as Uploadify, Blueimp File upload, Valums File Uploader, ...
Those controls detect whether the browser supports the File API and it will use it. If it doesn't it will use other techniques such as using hidden <iframe>, Flash, Silverlight, ...

Java Web application, how to let a client save a generated .txt file?

I have a JSF Web application, and at some point i present the client a big chunk of information, I want to have a save as link, that allows the client to save this information on his computer as a .txt file.
Information on how to achieve this or a good tutorial would be great.
Does this work for you? You probably would need to set the ContentType to "application/octet-stream", otherwise the client's browser will display your text file instead of offering the option to "Save as".
I believe your best bet may be to have that link actually generate an Ajax call to generate the text file and set it as the src attribute of an iframe on the page. That will trigger (I think) the file download box.

Categories