![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
react-file-previewer
Advanced tools
A browser/device-agnostic file previewer for PDF and image file types built on top of React-PDF.
A browser/device-agnostic file previewer for PDF and image file types built on top of React-PDF.
npm i react-file-previewer
This component supports URLs and base64 encoded data.
import FilePreviewer from 'react-file-previewer';
export const App = () => (
<div>
<h1>My App</h1>
<FilePreviewer file={{
url: "https://cors-anywhere.herokuapp.com/http://africau.edu/images/default/sample.pdf"}}
/>
</div>
);
import FilePreviewer from 'react-file-previewer';
export const App = () => (
<div>
<h1>My App</h1>
<FilePreviewer
file={{
data: "<base64 string>",
mimeType: 'application/pdf',
name: 'sample.pdf' // for download
}}
/>
</div>
);
import { useState } from 'react';
import FilePreviewer from 'react-file-previewer';
const PDF1_URL =
'https://cors-anywhere.herokuapp.com/http://africau.edu/images/default/sample.pdf';
export const App = () => {
const [file, setFile] = useState({ url: PDF1_URL });
const onFileChange = event => {
const fileReader = new window.FileReader();
const file = event.target.files[0];
fileReader.onload = fileLoad => {
const { result } = fileLoad.target;
setFile({ url: result });
};
fileReader.readAsDataURL(file);
};
return (
<div>
<h1>My App</h1>
<input type="file" onChange={onFileChange} />
<FilePreviewer
file={file}
/>
</div>
)
};
This will render the first page of the file as a thumbnail. It takes the exact same props as the default export
FilePreviewer
.
import {FilePreviewerThumbnail} from 'react-file-previewer';
export const App = () => (
<div>
<h1>My App</h1>
<FilePreviewerThumbnail
file={{
data: "<base64 string>",
mimeType: 'application/pdf',
name: 'sample.pdf' // for download
}}
/>
-or-
<FilePreviewerThumbnail file={{
url: "https://cors-anywhere.herokuapp.com/http://africau.edu/images/default/sample.pdf"}}
/>
</div>
);
Prop name | Type | Description |
---|---|---|
file | object | Refer to file object |
onClick | function | Event handler for when viewer is clicked |
hideControls | bool | If 'true', viewer won't display the zoom, page up/down, and fit-to-screen controls |
Prop name | Type | Description |
---|---|---|
file | object | Refer to file object |
onClick | function | Event handler for when viewer is clicked |
hideControls | bool | If 'true', viewer won't display the zoom, page up/down, and fit-to-screen controls |
style | object | Any css style overrides |
Prop name | Type | Description |
---|---|---|
url | string | This can be used by itself with no other prop |
data | string | Base64 encoded string of file. If used, mimeType must also be provided |
mimeType | string | Type of the file |
name | string | Used to specify the filename when download button is clicked |
FAQs
A browser/device-agnostic file previewer for PDF and image file types built on top of React-PDF.
The npm package react-file-previewer receives a total of 586 weekly downloads. As such, react-file-previewer popularity was classified as not popular.
We found that react-file-previewer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.