All Projects β†’ johndatserakis β†’ file-upload-with-preview

johndatserakis / file-upload-with-preview

Licence: MIT license
πŸ–Ό Simple file-upload utility that shows a preview of the uploaded image. Written in TypeScript. No dependencies. Works well with or without a framework.

Programming Languages

typescript
32286 projects
SCSS
7915 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to file-upload-with-preview

react-file-input-previews-base64
This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.
Stars: ✭ 15 (-96.31%)
Mutual labels:  input, upload, file, preview
File Upload With Preview
πŸ–Ό A simple file-upload utility that shows a preview of the uploaded image. Written in pure JavaScript. No dependencies. Works well with Bootstrap 4 or without a framework.
Stars: ✭ 352 (-13.3%)
Mutual labels:  input, upload, file, preview
PHP-FileUpload
Simple and convenient file uploads β€” secure by default
Stars: ✭ 53 (-86.95%)
Mutual labels:  input, upload, file
Ngx Material File Input
File input for Angular Material form-field
Stars: ✭ 193 (-52.46%)
Mutual labels:  input, upload, file
ngx-dropzone
A highly configurable dropzone component for Angular.
Stars: ✭ 123 (-69.7%)
Mutual labels:  upload, file, preview
react-simple-file-input
Simple wrapper for the HTML input tag and HTML5 FileReader API
Stars: ✭ 29 (-92.86%)
Mutual labels:  input, upload, file
Uploadcare Widget
Uploadcare Widget, an ultimate tool for HTML5 file upload supporting multiple file upload, drag&drop, validation by file size/file extension/MIME file type, progress bar for file uploads, image preview.
Stars: ✭ 183 (-54.93%)
Mutual labels:  upload, file
Publicleech
can be found on Telegram as https://telegram.dog/PublicLeechGroup
Stars: ✭ 236 (-41.87%)
Mutual labels:  upload, file
Vue Picture Input
Mobile-friendly picture file input Vue.js component with image preview, drag and drop, EXIF orientation, and more
Stars: ✭ 862 (+112.32%)
Mutual labels:  input, preview
Laravel Filemanager Example 5.3
Demo integration for laravel-filemanager (https://github.com/UniSharp/laravel-filemanager).
Stars: ✭ 100 (-75.37%)
Mutual labels:  upload, file
svelte-filepond
πŸ”Œ A handy FilePond adapter component for Svelte
Stars: ✭ 188 (-53.69%)
Mutual labels:  upload, file
ic-firebase-uploader
This component is a multi-file uploader for firebase
Stars: ✭ 21 (-94.83%)
Mutual labels:  upload, file
React Files
A file input (dropzone) management component for React
Stars: ✭ 126 (-68.97%)
Mutual labels:  upload, file
Jquery Filepond
πŸ”Œ A handy FilePond wrapper for jQuery
Stars: ✭ 124 (-69.46%)
Mutual labels:  upload, file
file-input-accessor
Angular directive that provides file input functionality in Angular forms.
Stars: ✭ 32 (-92.12%)
Mutual labels:  input, file
Laravel Filemanager
Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
Stars: ✭ 1,688 (+315.76%)
Mutual labels:  upload, file
Vue Filepond
πŸ”Œ A handy FilePond adapter component for Vue
Stars: ✭ 1,263 (+211.08%)
Mutual labels:  upload, file
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (-77.34%)
Mutual labels:  upload, file
react-magic-dropzone
✨Magically drag and drop files/links for uploading
Stars: ✭ 11 (-97.29%)
Mutual labels:  input, upload
mat-file-upload
A simple & configurable Angular Material file upload component.
Stars: ✭ 14 (-96.55%)
Mutual labels:  upload, file

file-upload-with-preview

πŸ–Ό Simple file-upload utility that shows a preview of the uploaded image. Written in TypeScript. No dependencies. Works well with or without a framework.

NPM Version NPM Downloads License Tweet

Links

Install

yarn add file-upload-with-preview

Or, you can include it through the browser.

<link
  rel="stylesheet"
  type="text/css"
  href="https://unpkg.com/file-upload-with-preview/dist/file-upload-with-preview.min.css"
/>

<script src="https://unpkg.com/file-upload-with-preview/dist/file-upload-with-preview.iife.js"></script>

About

This is a simple frontend utility meant to help the file-upload process on your website.

It is written in pure JavaScript and has no dependencies. You can check out the live demo here.

For the most part, browsers do a good job of handling image-uploads. That being said - I find the ability to show our users a preview of their upload can go a long way in increasing the confidence in their upload.

file-upload-with-preview aims to address the issue of showing a preview of a user's uploaded image in a simple to use package.

Features

  • Shows the actual image preview in the case of a single uploaded .jpg, .jpeg, .gif, or .png image. Shows a success-image in the case of an uploaded .pdf file, uploaded video, or other un-renderable file - so the user knows their image was collected successfully. In the case of multiple selected files, the user's selected images will be shown in a grid.
  • Shows the image name in the input bar. Shows the count of selected images in the case of multiple selections within the same input.
  • Allows the user to clear their upload and clear individual images in the multiple grid
  • Looks great
  • Framework agnostic - to access the uploaded file/files just use the cachedFileArray (always will be an array) property of your FileUploadWithPreview object.
  • For every file-group you want just initialize another FileUploadWithPreview object with its own uniqueId - this way you can have multiple file-uploads on the same page. You also can just use a single input designated with a multiple property to allow multiple files on the same input.

Usage

This library looks for a specific HTML element to display the file-upload. Simply add the below div to your HTML. Make sure to populate your unique id in the data-upload-id attribute.

<div class="custom-file-container" data-upload-id="myFirstImage"></div>

Then, initialize your file-upload in the JavaScript like below:

import { FileUploadWithPreview } from 'file-upload-with-preview';
import 'file-upload-with-preview/dist/file-upload-with-preview.min.css';

const upload = new FileUploadWithPreview('myFirstImage');

If you're importing directly in the browser, use the following instead:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <link
      rel="stylesheet"
      type="text/css"
      href="https://unpkg.com/file-upload-with-preview/dist/file-upload-with-preview.min.css"
    />
  </head>
  <body>
    <div class="custom-file-container" data-upload-id="myFirstImage"></div>
    <script src="https://unpkg.com/file-upload-with-preview"></script>
  </body>
</html>

Then initialize like this:

const upload = new FileUploadWithPreview.FileUploadWithPreview('myFirstImage');

Then when you're ready to use the user's file for an API call or whatever, just access the user's uploaded file/files in the cachedFileArray property of your initialized object like this:

upload.cachedFileArray;

You can optionally trigger the image browser and clear selected images programmatically. There are additional methods on the class if you'd like to take a look at the source code.

upload.emulateInputSelection(); // to open image browser
upload.resetPreviewPanel(); // clear all selected images

You may also want to capture the event when an image is selected.

import { Events, ImageAddedEvent } from 'file-upload-with-preview';

window.addEventListener(Events.IMAGE_ADDED, (e: Event) => {
  const { detail } = e as unknown as ImageAddedEvent;

  console.log('detail', detail);
});

Note

The cachedFileArray property is always an array. So if you are only allowing the user to upload a single file, you can access that file at cachedFileArray[0] - otherwise just send the entire array to your backend to handle it normally.

Make sure to pass in multiple: true in your options if you want to allow the user to select multiple images.

Docs

View the full docs here.

Full Example

See the full example in the ./example/index.ts folder. See the top of this README for some links to a few live CodeSandbox's.

Browser Support

If you are supporting a browser like IE11, one way to add a polyfill for fetch and promise is by adding the following in the bottom of your index.html:

<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>

Development

# Install dependencies
yarn

# Watch changes during local development
yarn dev

# Run tests
yarn test

# Build library
yarn build

Other

Go ahead and fork the project! Submit an issue if needed. Have fun!

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].