tj-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i tj-sdk

Weekly Downloads

1

Version

0.3.3

License

MIT

Unpacked Size

6.69 kB

Total Files

7

Last publish

Collaborators

  • jackrobertscott