
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
reactjs-file-preview
Advanced tools
Effortlessly preview images, videos, and PDFs in your React applications with MyFilePreview. This lightweight and customizable component intelligently detects file types and displays them.
Effortlessly preview images, videos, and PDFs in your React applications with reactjs-file-preview. This lightweight and customizable component intelligently detects file types and displays:
Perfect for file upload interfaces, document management systems, and media galleries! 🚀
Live Demo: https://akshay2002singh.github.io/reactjs-file-preview/
npm install reactjs-file-preview
# OR
yarn add reactjs-file-preview
import React from "react";
import FilePreview from "reactjs-file-preview";
const App = () => {
return (
<div>
<h2>File Preview Example</h2>
<FilePreview preview="https://example.com/sample.pdf" />
</div>
);
};
export default App;
<FilePreview
preview="https://example.com/sample.jpg"
placeHolderImage="https://example.com/placeholder.png"
errorImage="https://example.com/error.png"
/>
import sampleImg from "../assets/exampleImage.png";
<div style={{ width: "300px" }}>
<FilePreview preview={sampleImg} />
</div>;
<input
type="file"
onChange={(e) => e.target.files && setFile(e.target.files[0])}
style={{ marginBottom: "1rem" }}
/>
<div style={{ width: "600px", height: "400px", borderRadius: '12px', overflow:'hidden' }}>
<FilePreview
preview={file ?? ""}
placeHolderImage="https://placehold.co/600x400/fff/000?text=Placeholder"
errorImage="https://placehold.co/600x400/fff/FF0000?text=Error"
/>
</div>
If your files require authentication or are behind CORS restrictions, you can pass a custom Axios instance:
import axios from "axios";
const customAxios = axios.create({
headers: {
Authorization: "Bearer YOUR_ACCESS_TOKEN",
},
});
<FilePreview
preview="https://example.com/protected-file.pdf"
axiosInstance={customAxios}
/>;
reactjs-file-preview currently supports the following file extensions:
jpg, jpeg, png, gif, webpmp4, webm, ogg| Prop Name | Type | Required | Description |
|---|---|---|---|
preview | string | File | null | ✅ | The source of the file to preview. Supports: • Remote URL (string) • Local file import via bundler ( import sample from "./file.png") • File object from an <input type="file" />• null (shows the placeholder if provided) |
clarity | string | ❌ | Defines clarity of the file being previewed. Defaults to 1000. Higher the value, more the loading time of the file. |
placeHolderImage | string | ❌ | URL of an image to display if no file is provided. |
errorImage | string | ❌ | URL of an image to display if the file fails to load. |
fileType | string | ❌ | Type of the file (image, video, pdf). If not provided, the type will be auto-detected. |
axiosInstance | object | ❌ | Custom Axios instance for fetching files, useful for handling authentication or CORS issues. |
ℹ️ Note:
Ifpreviewis not provided (or isnull) and aplaceHolderImageis supplied, the placeholder image will be shown automatically.
This component will automatically detect the file type and display the appropriate preview. 🎉
Start using reactjs-file-preview today and enhance your file preview experience! 🎉
FAQs
Effortlessly preview images, videos, and PDFs in your React applications with MyFilePreview. This lightweight and customizable component intelligently detects file types and displays them.
The npm package reactjs-file-preview receives a total of 1,723 weekly downloads. As such, reactjs-file-preview popularity was classified as popular.
We found that reactjs-file-preview demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.