Download files from web page - java

I want to download pdf files from http://bookzz.org/ using java. How I can pass a file name to the site and get list to choose from? How can I make all these steps run in the background?

You can use e.g. HtmlUnit to access a web site via java.
You can use this to perform searches in the form and than use the links to download the files.

Related

Upload image automatically to instagram with Selenium in java

I am using Selenium and I need to upload an image to instagram. But at the time the windows file selector opens I could not get it to search for the image and upload it automatically
Up to this point my application opens well, when it goes to the point of selecting the file it does not do it automatically
I tried using the following codes without success
driver.findElement(By.className(name)).send_keys('C:\\path-to-file\\file.jpg')
But it gives me back the value of the second photo, that is, it generates a file selector from the main folder and not the one that I pass through as a parameter
I am using the following versions:
Java: 8
Selenium: 3.14
ChromeDriver: 76
Normal browsers don't allow JavaScript any access to the local disk. This is basic security. Imagine what would happen if you visit some site and it reads your local password file or any other important data without asking you.
If you want to upload files, take some standalone application or write a small utility that will do that. For instance, try instapy, you can find it pypi.org or on github. It is a matter of taste, the other can prefer other tools. Just try several tools and see which fits your need better.
The window opened for file explorer is not part of the browser and therefore it can not be interacted with via selenium. The solution to this is a software called AutoIt. Use the following link for a guide on how to use AutoIt for file uploads : Link

access file-system file with my browser

Can i access my local file system files with my browser? I think it is possible, I found one mozilla firefox plugin which does the same.
As per my understanding, the way upload functionality of a browser works, in the same way we can do traversing of files.
Please provide provide me some link to know about the "upload functionality" of a browser, how does it contact to the filesystem to upload any file from a given path.
Or can I write ay client side script which can do traversing?
If you're just wanting to let the client upload a file, there's no need for plugins or Java or anything such. Just use FileUpload in a form.

How to add Header/Footer in Google Drive from Java API?

I converting HTML file to PDF via Google Drive Service. I want to add Header and Footer on pages. How can do that using Java Google Drive API?
PS: If there is not proper way than any workaround would be appreciated.
I don't think you can do this directly using Google Drive API. If you are fine with some workaround, I would use Google Apps Script FooterSection Class:
Upload file using Files.insert() with option convert=true
Either trigger or keep running script on specific folder which does the following:
Modify Footer using FooterSection Class
Export Google Document file as PDF
In order to export PDF, there are two ways I can think of.
Using Document Class of Apps script
doc.getAs("application/pdf")
Or getting export link of PDF from Google Drive API using Files.list() where you can get downloadable link for PDF.
"exportLinks": {
"application/pdf": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=pdf",
"application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=ods",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=xlsx"
},

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, ...

Categories