Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rpldy/upload-preview

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rpldy/upload-preview

preview component to show image or video being uploaded

  • 0.13.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5K
decreased by-12.32%
Maintainers
1
Weekly downloads
 
Created
Source
npm version circleci status codecov status bundlephobia badge rpldy storybook

Upload Preview

Preview component to show image or video being uploaded.

By default, will present a preview of the file being uploaded in case its an image or video.

Installation

#Yarn: 
   $ yarn add @rpldy/uploady @rpldy/upload-preview 

#NPM:
   $ npm i @rpldy/uploady @rpldy/upload-preview 

Props

Name (* = mandatory)TypeDefaultDescription
loadFirstOnlybooleanfalseload preview only for the first item in a batch
maxPreviewImageSizenumber2e+7maximum size of image to preview
maxPreviewVideoSizenumber1e+8maximum size of video to preview
fallbackUrlstring | FallbackMethodundefinedstatic URL or function that returns fallback in case failed to load preview or when file over max size
imageMimeTypesstring[]see list belowimage mime types to load preview for
videoMimeTypesstring[]see list belowvideo mime types to load preview for
previewComponentPropsPreviewComponentPropsOrMethodundefinedobject or function to generate object as additional props for the preview component
PreviewComponentReact.ComponentTypeimg | videoThe component that will show the preview
rememberPreviousBatchesbooleanfalseshow previous batches' previews as opposed to just the last
previewMethodsRefReact Refundefinedref will be set with preview helper methods
onPreviewsChanged(PreviewItem[]) => voidundefinedcallback will be called whenever preview items array changes

Example


import React from "react";
import Uploady from "@rpldy/uploady";
import UploadPreview from "@rpldy/upload-preview";

export const App = () => (
     <Uploady destination={{ url: "my-server.com/upload" }}>     
        <UploadPreview
            fallbackUrl="https://icon-library.net/images/image-placeholder-icon/image-placeholder-icon-6.jpg"/>
    </Uploady>
);

Advanced Usage

_The props rememberPreviousBatches, previewMethodsRef, and onPreviewsChanged make it possible to do more with previews. Specifically, the make it possible to create a visual queue of the uploads.

This is especially useful when adding other features such as abort and retry.

The code below shows how to clear the previews with a button click:

import React from "react";
import Uploady from "@rpldy/uploady";
import UploadPreview from "@rpldy/upload-preview";
import UploadButton from "@rpldy/upload-button";

const PreviewsWithClear = () => {
	const previewMethodsRef = useRef();
	const [previews, setPreviews] = useState([]);

	const onPreviewsChanged = useCallback((previews) => {
		setPreviews(previews);
	}, []);

	const onClear = useCallback(() => {
		if (previewMethodsRef.current?.clear) {
			previewMethodsRef.current.clear();
		}
	}, [previewMethodsRef]);

	return <>
		<button onClick={onClear}>
            Clear {previews.length} previews
        </button>
		<br/>		
        <UploadPreview
            rememberPreviousBatches            
            previewMethodsRef={previewMethodsRef}
            onPreviewsChanged={onPreviewsChanged}
        />            		
	</>;
};

export const App = () => {	
	return <Uploady destination={{ url: "my-server.com/upload" }}>
		<UploadButton />
		<PreviewsWithClear />
	</Uploady>;
};

Custom Preview

For an example of using a custom preview component see this story.

Default image types

  • "image/jpeg"
  • "image/webp"
  • "image/gif"
  • "image/png"
  • "image/apng"
  • "image/bmp"
  • "image/x-icon"
  • "image/svg+xml"

Default video types

  • "video/mp4"
  • "video/webm"
  • "video/ogg"

FAQs

Package last updated on 29 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc