npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multiple-sources-uploader

v1.1.3

Published

Upload a photo from your local files, camera or your favorite social networks like Facebook, Google Photos or Instagram

Downloads

16

Readme

multiple-sources-uploader

Lightweight (~20Kb minified & gziped) uploader that connects with social medias.

alt preview

Why?

I couldn't find any package that would help me getting photos from social media APIs. The closest thing I found was cloudinary/uploadcare widgets, which are quite heavy (not acceptable on mobile) and restricted to use with their services.

Also, I didn't like the idea of uploading big photos and to resize them on the server. That's why I included a cropper and a resizer (based on pica - high quality resizer) to this uploader. This way, you'll only upload what you need and save bandwith & storage space (plus time for your users). As a bonus, it can convert your photos to webp if your browser support it.

When I resized a 5.7Mb photo to 1000x1000, its final weight was only 56Ko (webp format). Pretty smooth to upload, right?

Features

Upload any photos from:

  • your computer
  • your webcam/phone camera
  • Facebook
  • Google Photos
  • Instagram

Edit them:

  • crop (+ aspect ratio)
  • rotate
  • mirror
  • resize

Work on small and big screens :)

Documentation

Constructor

import MSUploader from 'multiple-sources-uploader'

MSUploader(options)

Options

Uploader

| param name | description | | ------------ | ---------------------------------------------------------------------------------------------------- | | url | Required. Your upload url. | | | method | The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). Default: POST | | getSignature | Function that should retrieve signature fields and pass it to its callback param (see example below) | | onStart | Function triggered when upload starts. A blob representing the photo is passed as first arg. | | onProgress | Function triggered when uploading. Percent of completion is passed as first arg. | | onDone | Function triggered when upload is succesful. The XMLHttpRequest object is passed as first arg. | | onError | Function triggered if the upload fails. The XMLHttpRequest object is passed as first arg. |

Note:

  • The popup will close right after the upload starts.
  • The user will get an alert if he tries to leave the page while an upload is still active.
  • We recommend to disable the submit button of your form 'onStart' and to reactivate it 'onDone'.

Cropper

| param name | description | | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ratio | Object with v & h keys representing the ratio. (eg: 16/9 => { v: 16, h: 9 }). Crop will be free if not set. | | minWidth | The minimum width your image should be. It means the cropper won't load an image that doesn't have its min dimension (it'll also take the aspect ratio into account) & will limit you when zooming or downsizing the cropping area. | | resizeToWidth | Resize the picture to this width (keeping the aspect ratio) | | upscale | Will resize the photo to resizeToWidth even if it's originally smaller. Default: false | | webpIfSupported | Convert the photo to webp if the user's browser support it. Fallback to jpg otherwise. Default: false |

Local

| param name | description | | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | accept | Similar to the input file attribute. You can specify a list of MIME types (eg: 'image/png,image/gif'), a list of extensions (eg: '.jpg,.jpeg,.gif'), or accept all kind of images ('image/*'). Default: 'image/jpeg,image/gif,image/png,image/webp' |

Note:

  • the cropper will only be compatible with the formats your browser can read
  • if you specify webp, it will only accept this type of images if your browser support it

Facebook

| param name | description | | ----------- | ------------------------------------------------------------------------------------------------------------------------ | | appId | Required. Your facebook app Id. | | locale | Required. Locale used with the API. Supported locales. | | itemsToLoad | Number of albums or photos to load on each request. Default: 24 |

Google Photos

| param name | description | | ------------- | ---------------------------------------------------------------------------------------------------- | | oAuthClientID | Required. Google APIs oAuth client ID | | itemsToLoad | Number of albums or photos to load on each request. Default: 24 |

Instagram

| param name | description | | ----------- | ---------------------------------------------------------------------------------------- | | clientID | Instagram authentication clientID | | itemsToLoad | Number of photos to load on each request. Default: 24 |

Note: To deactivate a social media, set its options to null.

Example (with amazon s3 upload)

MSUploader({
  uploader: {
    url: 'https://my-bucket.s3.amazonaws.com',
    getSignature: callback => {
      // Retrieve s3 presigned post fields from your server
      fetch('/s3_signature')
        .then(response => response.json())
        .then(callback)
    },
    onStart: blob => {
      // You can use the blob to display a preview.
      // Don't forget to call URL.revokeObjectURL once the img is loaded
      document.querySelector('img').src = URL.createObjectURL(blob)
      // Ensure to get the photo URL before the user submit his form
      document.querySelector('[type="submit"]').disabled = true
    },
    onProgress: progress => {
      console.log(`${progress}%`)
    },
    onError: xhr => {
      console.log(`Yikes. Something wrong happened.`)
    },
    onDone: xhr => {
      // Extract the URL from the response (specific to S3)
      const loc = xhr.responseXML.getElementsByTagName('Location')[0]
      const url = decodeURIComponent(loc.innerHTML)
      // Set your hidden field with the URL
      document.querySelector('[name="photo_url"]').value = url
      // Re-enable the form
      document.querySelector('[type="submit"]').disabled = false
    },
  },
  cropper: {
    ratio: { v: 1, h: 1 }, // square aspect ratio
    minWidth: 100,
    resizeToWidth: 1000,
    webpIfSupported: true,
  },
  local: {
    accept: 'image/jpeg,image/webp', // Only jpg/jpeg or webp
  },
  facebook: {
    appId: '...',
    locale: 'en_US',
  },
  googlePhotos: {
    oAuthClientID: '...',
  },
  instagram: {
    clientID: '...',
  },
})

i18n

MSUploader.setMessages({ ... }) provides a way to update all the texts. Look at the english messages (by default).

You can either use the translations in the locales/ folder, or to write your own (feel free to make a PR in this case so everybody can use it=)

import MSUploader from 'multiple-sources-uploader'
import fr from 'multiple-sources-uploader/lib/locales/fr'

MSUploader.setMessages(fr)

Css

You can find it in the dist/ folder. Look at the sources to easily override them.

import MSUploader from 'multiple-sources-uploader'
import 'multiple-sources-uploader/dist/ms-uploader.css'