0.3.3 • Published 4 years ago

tj-sdk v0.3.3

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

tj

🛰 Simple image uploader for the browser

TJ provides a simple interface for uploading and hosting images on AWS.

Install

Using npm:

npm install --save tj

Setup

Configure a new tj instance.

import TJ from 'tj'

const tj = new TJ()

Upload

TJ currently supports image uploading.

tj.image({
    file: files[0],
    compressed: true,
    height: 300,
    width: 400,
    crop: {
      x: 0,
      y: 0,
    },
  })
  .then(image => {
    console.log(`Url: ${image.url}`)
    console.log(`Id: ${image.id}`)
  })
  .catch(error => {
    console.warn(`Error: ${error.message}`)
  })

React

Simple example of how to use TJ with React.

import React, { useEffect } from 'react'
import tj from '../utils/tj'

export const Uploader = ({ onImage }) => {
  const [error, setError] = useState()
  const onImageChange = event => {
    const files = event.target.files
    if (files && files.length) {
      tj.image({
        file: files[0],
        compressed: true,
        height: 300,
        width: 400,
      })
      .then(image => onImage(image))
      .catch(e => setError(e))
    }
  }
  return (
    <div>
      {error && <div>Error: {error.message}</div>}
      <input 
        id="avatar"
        type="file"
        accept="image/png, image/jpeg"
        onChange={onImageChange}
      />
    </div>
  )
}

Credits

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago