How to get the user upload file path in Java

Asked

Viewed 1,321 times

-2

Hello, I am creating a web page with an iframe, and I would like to change the src of this iframe to the user upload path, I would like to know how I can do it, follow code:

<input type="file">
<div class="framePDF">
    <iframe id="frames" style="WIDTH: 100%; HEIGHT: 650px"  src="Desenvolvimento WEB com HTML, CSS e JavaScript.pdf;embedded=true" frameBorder=0;></iframe>
</div>

My iframe code is fixed, but I would like to change it as the user chooses the file

  • You want to display the client’s local file?

  • Yes, that’s exactly it...

  • is not possible, will appear as fakepath

  • Actually your question does not make much sense... you want to display in the browser a file that is on the client’s machine instead of uploading?

1 answer

0

Guys, I managed to solve the problem, I needed to create a file type input, and make a script code with Filereader, so it reads the file and presents

<input type='file' accept='file/*' onchange='openFile(event)'>

<div id="framePDF" class="framePDF" style="display: none">
        <br>
        <iframe id="frame" style="WIDTH: 100%; HEIGHT: 650px" frameBorder=0;></iframe>
        <!--O Comando iFrame permite criar um frame na página web para a leitura de um arquivo PDF -->
    </div>

    <script>
        var openFile = function(event) {
            var input = event.target;

            document.getElementById('framePDF').style.display = 'block';

            var reader = new FileReader();
            reader.onload = function() {
                var dataURL = reader.result;
                var output = document.getElementById('frame');
                output.src = dataURL;
            };
            reader.readAsDataURL(input.files[0]);
        };
    </script>

I appreciate your help... With this code, it creates an iframe, the user chooses a file from the machine itself, the script processes it, reads it, and places the information inside the iframe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.