I have made the servlets both to download and upload the file independently.
Now I need to write a JavaScript code such that as soon as I upload a file a link appears in another HTML page to download that file.
you can use AJAX to upload the file and then generate the response to get information about your file to create a link for it. I used the following jquery plugin to implement it.
Java Form Plugin
Related
Is there a way to download files attached using Paperclip without using libraries?
My goal is to allow the user to download the file as soon as the file is uploaded and before it is sent to the backend.
I found the way to make it working with file-saver
However, I was wondering if that can be done without the library?
You can use the js-file-download package.
https://www.npmjs.com/package/js-file-download
All examples I see on the HTML5/JS File API read the file by letting the user select the file first using
<input type="file">
I want to be able to read the contents of the file using a URL/path to the file. How can I achieve that?
This can not be done from the browser for security purposes.
I've seen a few tutorials of how to use Html5 File API such as this https://www.html5rocks.com/en/tutorials/file/dndfiles/ for file uploading. What I want is a few pointers of how to send all that from a browser to backend and process it there to actually upload files. In those tutorials it's not shown.
The backend language doesn't matter.
And I don't want to use an external js library, only pure javascript.
I have a php script to download some webpages. The problem is that the downloaded files haven't got the dynamic content which is written by javascript.
I suppose I need a javascript engine or something similar. Is there some php library or command-line program for downloading a webpage with all its dynamic content?
Example of what I need: I want to download the webpage www.example.com/product.html.
Now: I'm able to download the code:
<h1></h1>
What I want: I want to download the code:
<h1>Title written by javascript</h1>
This is happening because the JavaScript is not downloaded properly. You are only downloading the HTML file and not the attached JavaScript files.
Once the JavaScript will be available for the HTML page, all the dynamic content would be coming correctly.
Another Workaround:
You can use selenium like web automation libraries that actually opens the page in a browser, let the browser execute the js and prepare the DOM. After this you can download the HTML content.
One more:
You can make use of PhantomJs to download the HTML page, process the Javascript and give you the final output for save.
https://superuser.com/questions/448514/command-line-browser-with-js-support
In jQuery, I used file input type to upload a file. But now I want to show the content of that uploaded file on the browser without having any communication with the server side.
Is this possible and if so how to that.
You can try HTML5 File API:
Using the File API added to the DOM in HTML5, it's now possible for web content to ask the user to select local files, then read the contents of those files.
HTML5 File API is the answer to what to need. Here is a complete working example of what you want:
http://www.html5rocks.com/en/tutorials/file/dndfiles/