files-ui-main-logo
Files ui

File Download

In this page you will find some demos for downloading files with <FileMosaic/> and <FileCard/> components.

Same origin URL

When only downloadUrl is specified, FileMosaic will perform the download only for same-origin URLs since it uses the anchor tag under the hood.
NarutoAndSasukevsMomoshiiki.mp4
NarutoAndSasukevsMomoshiiki.mp4
28.00 MB
video/mp4

Different origin URL and 'downloadUrl' prop specified

When only downloadUrl is specified and if the resource is located in any other host (on Stean for instance), the component will open a new tab and display the content.
blur Thor.jpeg
Thor.jpeg
blur Thor.jpeg
Thor.jpeg
28.00 MB
image/jpeg

Different origin URL and 'onDownload' prop specified

For avoiding the behaviour described above, you can do you own download implementation by overriding the download function by setting the onDownload prop. There is an example of how to do it with pure javascript.
The approach we use here can be summerized in 4 steps:
  1. Make a GET request with fetch API (you can use axios or any other way to fetch resources from internet).
  2. Create an Object URL from the Blob file.
  3. Create an anchor tag set the attributes, append it to the document, and click it programatically.
  4. Finally, revoke the Object URL and remove the anchor from document.
blur Thor.jpeg
Thor.jpeg
blur Thor.jpeg
Thor.jpeg
28.00 MB
image/jpeg

API

See the documentation below for a complete reference to all of the props available to the components mentioned here.