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

react-firebase-file-upload

v3.0.3

Published

Firebase File Uploader

Downloads

46

Readme

react-firebase-file-upload

Firebase V9 File Upload

NPM JavaScript Style Guide

Install

npm install --save react-firebase-file-upload

Usage

Full Example

Note Please specify the exact file type you want to accept as shown the example below. Don't use wildcard characters such as image/* in accept parameter. For now, accept parameter will make sure users select ONLY the accepted files if you specified in full. I'm working on validating accept parameter with wildcard characters soon.

import React from 'react'
import { initializeApp } from 'firebase/app'
import { getStorage } from 'firebase/storage'
import { useFileUpload } from 'react-firebase-file-upload'

// Set the configuration for your app
// TODO: Replace with your app's config object
const firebaseConfig = {
  apiKey: '<your-api-key>',
  authDomain: '<your-auth-domain>',
  storageBucket: '<your-storage-bucket-url>'
}
const firebaseApp = initializeApp(firebaseConfig)

// Get a reference to the storage service, which is used to create references in your storage bucket
const storage = getStorage(firebaseApp)

const App = () => {
  const _input = useFileUpload(storage, {
    // the type of files to upload
    accept: 'image/png, image/jpeg, image/jpg, image/webp',
    // whether to accept multiple files or just one
    multiple: true,
    // where you want to save the uploaded files in firebase storage
    path: `profile-pictures`
  })

  // props for file input
  const {
    /** Input type */
    type,
    /** Accepted file types (e.g. "image/png, image/jpeg") */
    accept,
    /** Allow multiple files to be selected */
    multiple,
    /** Disable input */
    disabled,
    /** onChange event to set selected files */
    onChange,
    /** Selected files */
    files,
    /** Loading state */
    loading,
    /** Error message */
    error,
    /** Upload progress for each file */
    progress,
    /** Upload status for each file */
    status,
    /** Download URL for each file */
    downloadURL,
    /** Upload complete state */
    isCompleted,
    /** Upload files to firebase storage */
    onUpload,
    /** Reset states when finished uploading */
    onUploadComplete,
    /** Remove file from selected files */
    onRemove
  } = _input

  return (
    <>
      <input
        type={type}
        accept={accept}
        multiple={multiple}
        disabled={disabled}
        onChange={onChange}
      />

      {files &&
        files.map((file, index) => (
          <div key={index}>
            {file.type?.includes('image') && (
              <img
                src={URL.createObjectURL(file)}
                alt='preview'
                style={{
                  width: '100px',
                  height: '100px',
                  objectFit: 'cover'
                }}
              />
            )}
            <p>{file.name}</p>
            <p>{file.size}</p>
            <p>{file.type}</p>
            <button onClick={() => onRemove(file)}>Remove</button>
          </div>
        ))}
      {loading && <p>Loading...</p>}

      {error && <p>Error: {error}</p>}

      {status &&
        Object.keys(status).map((key, index) => (
          <p key={index}>
            {key}: {status[key]}
          </p>
        ))}

      {progress &&
        Object.keys(progress).map((key, index) => (
          <p key={index}>
            {key}: {progress[key]}%{' '}
          </p>
        ))}

      {isCompleted && (
        <button onClick={onUploadComplete}>Upload Complete</button>
      )}

      <button onClick={onUpload}>Upload</button>

      {downloadURL &&
        downloadURL.map((url, index) => (
          <img key={index} src={url} alt='uploaded' />
        ))}
    </>
  )
}

export default App

License

MIT © jamesofoaye