2

I am working on a java-based (webwork framework) web-app where the file to be uploaded needs to be compressed first. Since there's no way to set the value of "input type='file'" element via javascript, I decided to take the route of an embedded applet. Basically this applet compresses the chosen file, then uploads the compressed file to the server via scp.

It worked well, but I have issues regarding the rendering of the web page itself. I am thinking instead of implementing the file picker within the applet, if there's an existing file picker that I can use instead. Of course without putting any "input type='file'".

Links to these existing custom web file pickers will be very much appreciated.

2 Answers 2

4

This always works.

<div id="input_container" style="width: 0px; height: 0px; overflow: hidden"><input type="file" id="inputfile" /></div>
<div class="button" onclick="upload();">Upload file</div>

And your script

function upload(){
 document.getElementById('inputfile').click();
}

Your CSS

.button {
   /*button style here*/
}
Sign up to request clarification or add additional context in comments.

Comments

2

Due to security restrictions the only way to select a file with HTML is adding an <input type=file> to document. Then user should selects a file with real clicks.

Note that javascript is able (in modern browsers) to read the content of file, so it should not be able to select arbitrary file and read it.

1 Comment

Yeah, that's why I took the applet route and used jFileChooser. However, the rendering is so slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.