0

I want to submit a form with a file programmatically but i learned there is no way to pass file to input type="file" because of security. So i am searching a way to submit form with file from url. Html is below.

           <form class="converter-form" id="iri-converter-form">

            <label for="iri-converter-input">Custom Ontology:</label>

            <input type="text" id="iri-converter-input" placeholder="Enter ontology IRI">
            <button type="submit" id="iri-converter-button" disabled>Visualize</button>
          </form>

          <div class="converter-form">

            <input class="hidden" type="file" id="file-converter-input" autocomplete="off">

            <label class="truncate" id="file-converter-label" for="file-converter-input">Select ontology file</label>
            <button type="submit" id="file-converter-button" disabled>
              Upload
            </button>
          </div>
Ignazio
  • 10,504
  • 1
  • 14
  • 25

1 Answers1

0

You'll just want to pass the URL to the server. When the server receives the url, it will download the file to disk.

On the HTML/ javascript side of things, you'll probably want to show the Upload File input but give a button to upload from url. When they click that button, hide the upload file button and show a plain textbox for them to drop their url.

You may also want to check that the url is valid: Check if a Javascript string is a url

Also, make sure that the file type is one that you accept, there is always the possibility of malicious code being uploaded and run on the server

Tom G
  • 3,650
  • 1
  • 20
  • 19