How to add Media Downloader in Next.js ?
Last Updated :
26 Jul, 2024
In this article, we are going to learn how we can add Media Downloader in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally.
Approach: To add our Media Downloader we are going to use the react-use-downloader package. The react-use-downloader package helps us to add testimonials anywhere in our app. So first, we will install the react-use-downloader package and then we will add the Media Downloader on our homepage.
Create NextJS Application: You can create a new NextJs project using the below command:
npx create-next-app gfg
Install the required package: Now we will install the react-use-downloader package using the below command:
npm i react-use-downloader
Project Structure: It will look like this.

Adding the Media Downloader: We can easily add the media downloader in our app after installing the react-use-downloader package. For this example, we are going to add the media downloader to our homepage.
Add the below content in the index.js file:
index.js
import React from "react";
import useDownloader from "react-use-downloader";
export default function App() {
const { size, elapsed, percentage, download,
cancel, error, isInProgress } =
useDownloader();
const fileUrl = "/File.pdf";
const filename = "File.pdf";
return (
<div className="App">
<h3>GeeksforGeeks - File Downloader</h3>
<p>Download is in {isInProgress ?
"in progress" : "stopped"}</p>
<button onClick={() => download(fileUrl, filename)}>
Click to download the file
</button>
<button onClick={() => cancel()}>
Cancel the download
</button>
<p>Download size in bytes {size}</p>
<label for="file">Downloading progress:</label>
<progress id="file" value={percentage} max="100" />
<p>Elapsed time in seconds {elapsed}</p>
{error && <p>possible error {JSON.stringify(error)}</p>}
</div>
);
}
Explanation: In the above example first, we are importing the useDownloader component from the installed package. After that, we are adding our File and file names. Then we are adding a Progress bar, start downloading, and stop downloading buttons.
Steps to run the application: Run the below command in the terminal to run the app
npm run dev
Output:
Similar Reads
How to add Downloadable Spreadsheet in Next.js ? Adding a downloadable spreadsheet in a Next.js application involves several steps, including generating the spreadsheet file and providing a download link to the user. In this article, we are going to learn how we can add a downloadable spreadsheet in NextJS.ApproachTo add our downloadable spreadshe
2 min read
How to add File Dropper in Next.js ? Adding a file dropper feature in Next.js involves setting up a drag-and-drop interface, handling file uploads on the frontend, and processing the files on the server side. In this article, we are going to learn how we can add File Dropper in NextJS.ApproachTo add our File Dropper we are going to use
2 min read
How to add CodeBlock in Next.js ? In this article, we are going to learn how we can add CodeBlock in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditiona
2 min read
How to add ESLint in Next.js ? ESLint is a popular linting tool for identifying and fixing issues in JavaScript code. Adding ESLint to your Next.js project ensures that your code follows best practices and maintains a consistent style. This enhances code quality, helps catch errors early, and makes the codebase easier to maintain
3 min read
How to Load Data from a File in Next.js? Loading Data from files consists of using client-side techniques to read and process files in a Next.js application. In this article, we will explore a practical demonstration of Load Data from a File in Next.js. We will load a validated CSV input file and display its contents in tabular format. App
3 min read