In this article, we will guide you on how to customize a DataPage to allow your users to preview an image before they upload it.

Steps:

  1. Create a table that includes a File data type. Alternatively, make sure such a field already exists in the table you want to use.
  2. Edit a DataPage that contains the File field.
  3. Add a Header and Footer in the Web Form Wizard - Configure Fields screen of the DataPage wizard.
  4. Disable the HTML editor in the Footer section.
  5. Copy and paste the following code in the Footer section:
  6. Replace the FIELDNAME in the JavaScript code with the actual file field name (i.e., InsertRecordImage).
  7. Add an HTML block below the File field.
  8. Disable the HTML editor.
  9. Copy and paste the following code in the HTML block section: The image will be displayed in full size. If you want to display the image in a fixed size, add width and height:
  10. Save the DataPage.

Note: You can apply the JavaScript in the update form by following the steps above and changing InsertRecord to EditRecord in the JavaScript code.

Note: This article uses external HTML, JavaScript, or third-party solutions to add functionality outside of Caspio standard feature set. These solutions are provided “as is” without warranty, support or guarantee. The code within this article is provided as a sample to assist you in the customization of your web applications. You may need a basic understanding of HTML and JavaScript to implement successfully.

For assistance with further customization based on your specific application requirements, please contact our Professional Services team.

code1
 
<script>
document.getElementById("InsertRecordFIELDNAME").setAttribute("onchange","loadFile(event)");
    var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
  };
</script>
code2
<img id="output"/>
code3
<img id="output" width="300px" height="300px"/>