Input, Output & Result Handling›Preview & Download

Preview & Download

Use URL.createObjectURL() to expose a temporary browser URL for a returned File.

Download helper

function downloadFile(file) {
  const url = URL.createObjectURL(file);
  const a = document.createElement("a");
  a.href = url;
  a.download = file.name;
  a.click();
  setTimeout(() => URL.revokeObjectURL(url), 1000);
}

downloadFile(result.files[0]);

Image preview

const url = URL.createObjectURL(result.files[0]);
document.querySelector("#previewImage").src = url;

PDF preview

const url = URL.createObjectURL(result.files[0]);
document.querySelector("#pdfFrame").src = url;

Video preview

const url = URL.createObjectURL(result.files[0]);
const video = document.querySelector("#video");
video.src = url;
video.controls = true;
Revoke object URLs when the preview is replaced or no longer needed.