Digital Asset Management

Using the Filestack API, you can quickly build a powerful tool that allows your users to upload, store, remove and manage their digital assets efficiently.

Try it yourself:

  • Click on the “Upload” button to upload a new asset using the file picker.
  • Uploaded asset is shown in the asset table with “Remove”, “View”, and “Download” buttons.
  • Remove button using the remove() method of the client class to delete files permanently.
  • Download button using the preview() method of the client class to display images, PDFs, and other supported formats in a user-friendly interface.
  • For file metadata display, see the following example.
 
Result

Upload your files here

Terminal

npm install filestack-js tslib
HTML


Upload your files here

CSS
#demo-container{
    border: 2px dashed;
    padding: 10px;
} 

.asset-manage-btns{
    max-width: 30px;
    float:left;
    margin:7px;
    cursor:pointer;
}

#view-popup{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1412129e;
	  display: none;
}
	
#view-popup > div{
	  background: #eee;
    width: 50%;
    margin: 2% auto;
    padding-bottom: 20px;
}
	
#file-preview{
   padding: 20px;
   height: 600px;
}

#close-view{
    color: #EF4A25;
    font-size: 17px;
    text-decoration: underline;
    font-weight: 700;
}

#assets-table {
   border-collapse: collapse;
   border-spacing: 0;
   width: 100%;
   border: 1px solid #ddd;
}

#assets-table th, #assets-table td {
    text-align: left;
    padding: 16px;
}

#assets-table tr:nth-child(even) {
    background-color: #f2f2f2;
}
index.mjs

import * as filestack from "filestack-js";
window.addEventListener("DOMContentLoaded", function () {
  let newRow, uploadedFiles;
  
  //Replace Your_API_key with you API Key from DevPortal dev.filestack.com/login/
  const apikey = "Your_API_key";
  
  //Replace Your_POLICY_CODE with a real Policy created from your DevPortal dev.filestack.com/login/
  const p = "Your_POLICY_CODE";
  
  //Replace Your_SIGNATURE_CODE with a real SIGNATURE created from your DevPortal dev.filestack.com/login/
  const s = "Your_SIGNATURE_CODE";
  
  const security = {
    policy: p,
    signature: s
  };
  
  //File Picker configuration
  const pickerOptions = {
    maxFiles: 5,
    maxSize: 10 * 1024 * 1024,
    uploadInBackground: false,
    onUploadDone: (res) => {
      uploadedFiles = res.filesUploaded;
      for (var i = 0; i < uploadedFiles.length; i++) {
        const file = uploadedFiles[i];
        //HTML of the new row
        newRow = `
                  ${file.filename} 		
                  ${file.mimetype} 	
                      
                            

                     



  
                      

                      
                  `;
        //append the new row to the table
        document
          .getElementById("assets-table")
          .insertAdjacentHTML("beforeend", newRow);
        
      }
    }
  };

  const client = filestack.init(apikey);

  //Open the File Picker
  document.getElementById("picker").addEventListener("click", function (e) {
    e.preventDefault();
    client.picker(pickerOptions).open();
    return false;
  });

  //Close the preview popup
  document.getElementById("close-view").addEventListener("click", function (e)   {
    e.preventDefault();
    document.getElementById("view-popup").style.display = "none";
    document.getElementById("file-preview").innerHTML = "";
    return false;
  });
  
  document.getElementById("assets-table").addEventListener("click", (event) =>   {
    
    // Check if an SVG icon was clicked

    const svgAncestor = event.target.closest("svg");

    if (svgAncestor) {
      
      const svgId = svgAncestor.id;
      const parentTr = event.target.closest("tr");

      if (parentTr) {
        //get the asset handle
        let handle = parentTr.dataset.handle;

        if (svgId === "remove-asset") {
          client
            .remove(handle, security)
            .then((res) => {
              //Remove the entire table row when asser is removed
              parentTr.remove();
            })
            .catch((err) => {
              console.log(err);
            });
          
        } else if (svgId === "preview-asset") {
          
          // Display files in Filestack document viewer
          client.preview(handle, { id: "file-preview" });
          
          // Show the popup
          document.getElementById("view-popup").style.display = "block";
          
        } else if (svgId === "download-asset") {
          //Download asset
          client
            .download(handle, security)
            .then((res) => {
              const blob = res.data;
              const filename = res.headers["x-file-name"] || "downloaded-file.txt";
              downloadBlob(blob, filename);
            })
            .catch((err) => {
              console.log(err);
            });
        }
      }
    }

    function downloadBlob(blob, filename) {
      // Create a URL for the blob.
      const url = URL.createObjectURL(blob);

      // Create a temporary anchor element.
      const link = document.createElement("a");
      link.href = url;

      // Set the download attribute with the desired filename.
      link.download = filename;

      // Append the link to the document body (optional but good practice).
      document.body.appendChild(link);

      // Programmatically click the link to start the download.
      link.click();

      // Clean up by revoking the blob URL and removing the link.
      
      setTimeout(() => {
        URL.revokeObjectURL(url);
        document.body.removeChild(link);
      }, 800);
    }
  });
  
});

Start building your own file upload solution today.

PREVIEW

Users can preview their uploaded files directly inside the File Picker.

CONNECT TO 20+ CLOUD DRIVES

Connect your app directly to AWS, Facebook, Dropbox, Instagram, and more.

PROGRESS BAR UPLOADS

Give your users confidence that their files are on the way to the right destination.

MULTI-FILE UPLOADS

Let your users upload multiple files at one time for speed and simplicity.

CUSTOM CSS

Filestack blends seamlessly into your website or app. Ask about white-labeling.

CLIENT-SIDE CROP

Users can crop files to perfection before sending them to your website or app.

UNLIMITED UPLOADING

Upload any file type, from any local or cloud source, at any scale.

WEBSITES & HTML

Filestack can even load web content from any public URL and capture the rendered page as an image. Perfect for generating screenshots, previews, or converting HTML-based content into other formats.

SECURE CLOUD STORAGE

Store uploads directly in your cloud storage for ease and accessibility.
“Being smart here, in my opinion, is seriously looking at Filestack to give you a fantastic uploading experience, while you spend your time on your product vision, not already-solved problems.”
— CHRIS COYIER, FOUNDER OF CSS-TRICKS & CODEPEN