2.4.0 • Published 2 months ago

@bassem97/upup v2.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Goodbye to nasty configs, painful APIs and hello to a simple, easy to use, file uploader.

Installation

Install via NPM:

npm install @bassem97/upup 

Or via YARN:

yarn add @bassem97/upup

Usage

1 - Inside you component or App.tsx import UpupUploader and the types you need :

// imports
import {
  IBaseConfigs,
  ICloudStorageConfigs,
  IGoogleConfigs,
  IOneDriveConfigs,
  Is3Configs,
  UploadAdapter,
  UpupUploader,
} from '@bassem97/upup'

2 - Set your configurations keys from your .env file ( ex: .env.local ) :

const space_secret = process.env.NEXT_PUBLIC_UNOTES_SPACE_SECRET || ''
const space_key = process.env.NEXT_PUBLIC_UNOTES_SPACE_KEY || ''
const space_endpoint = process.env.NEXT_PUBLIC_UNOTES_SPACE_ENDPOINT || ''
const space_region = process.env.NEXT_PUBLIC_UNOTES_SPACE_REGION || ''
const document_space = process.env.NEXT_PUBLIC_UNOTES_DOCUMENT_SPACE || ''
const onedrive_client_id = process.env.NEXT_PUBLIC_ONEDRIVE_CLIENT_ID || ''
const google_client_id = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID_PICKER || ''
const google_app_id = process.env.NEXT_PUBLIC_GOOGLE_APP_ID || ''
const google_api_key = process.env.NEXT_PUBLIC_GOOGLE_API_KEY || ''

3 - Create 2 states one for key (which will be the final link of you file. ex: 'https://example-documents.nyc3.cdn.digitaloceanspaces.com/file.pdf') and another for canUpload ( which will be changed after uploading file and submitting )

const [key, setKey] = useState('');
const [canUpload, setCanUpload] = useState(false);

4 - initialize the configs from the provider you want to use ( ex: DigitalOceanSpaces, GoogleDrive, OneDrive, S3 )

const s3Configs: Is3Configs = {
  region: space_region,
  endpoint: space_endpoint,
  credentials: {
    accessKeyId: space_key,
    secretAccessKey: space_secret,
  },
};

const baseConfigs: IBaseConfigs = {
  canUpload: canUpload,
  setKey: setKey,
};

const cloudStorageConfigs: ICloudStorageConfigs = {
  bucket: document_space,
  s3Configs,
};

const googleConfigs: IGoogleConfigs = {
  google_api_key,
  google_app_id,
  google_client_id,
};

const oneDriveConfigs: IOneDriveConfigs = {
  onedrive_client_id,
  multiSelect: false,
};

4 - Render the UpupUploader component and pass the configs and the adapter you want to use :

return (
  <div>
    <UpupUploader
      baseConfigs={baseConfigs}
      cloudStorageConfigs={cloudStorageConfigs}
      googleConfigs={googleConfigs}
      oneDriveConfigs={oneDriveConfigs}
      uploadAdapters={[
        UploadAdapter.internal,
        UploadAdapter.google_drive,
        UploadAdapter.one_drive,
      ]}
    />
    <button onClick={() => setCanUpload(true)}> upload </button>
  </div>
);

5 - You can also use the UpupUploader component with the default configs and adapter :

return (
  <div>
    <UpupUploader
      baseConfigs={baseConfigs}
      cloudStorageConfigs={cloudStorageConfigs}
      uploadAdapters={[UploadAdapter.internal]}
    />
    <button onClick={() => setCanUpload(true)}> upload </button>
  </div>
);

All done! 🎉

Contributions

Contributions to this project are welcome! Feel free to submit issues or pull requests on the GitHub repository.

2.4.0

2 months ago

2.3.6

5 months ago

2.3.5

5 months ago

2.3.4

5 months ago

1.4.5

9 months ago

1.4.4

9 months ago

1.4.3

9 months ago

1.4.2

9 months ago

1.4.1

9 months ago

1.4.0

9 months ago

2.2.17

8 months ago

2.2.1

8 months ago

2.2.18

8 months ago

2.2.0

8 months ago

2.0.2

9 months ago

2.2.15

8 months ago

2.2.3

8 months ago

2.2.16

8 months ago

2.2.2

8 months ago

2.2.13

8 months ago

2.2.5

8 months ago

2.2.14

8 months ago

2.2.4

8 months ago

1.3.10

9 months ago

2.2.11

8 months ago

2.2.7

8 months ago

2.2.12

8 months ago

2.2.6

8 months ago

1.3.13

9 months ago

2.2.10

8 months ago

1.3.14

9 months ago

1.3.11

9 months ago

1.3.12

9 months ago

1.3.17

9 months ago

1.3.18

9 months ago

2.0.1

9 months ago

1.3.15

9 months ago

2.0.0

9 months ago

1.3.16

9 months ago

1.3.19

9 months ago

2.2.19

8 months ago

2.2.28

6 months ago

2.2.29

6 months ago

2.2.26

7 months ago

2.2.27

6 months ago

2.2.24

7 months ago

1.3.20

9 months ago

2.2.25

7 months ago

2.2.22

7 months ago

1.3.9

9 months ago

2.2.23

7 months ago

1.3.8

10 months ago

2.2.20

7 months ago

2.2.21

7 months ago

2.3.0

6 months ago

2.3.2

6 months ago

2.3.1

6 months ago

2.3.3

6 months ago

2.2.31

6 months ago

2.2.30

6 months ago

2.1.0

9 months ago

2.2.9

8 months ago

2.2.8

8 months ago

1.3.7

10 months ago

1.3.6

11 months ago

1.3.5

11 months ago

1.3.4

11 months ago

1.3.3

11 months ago

1.2.0

12 months ago

1.1.1

12 months ago

1.1.0

1 year ago

1.0.16

1 year ago

1.1.8

12 months ago

1.0.9

1 year ago

1.1.7

12 months ago

1.0.8

1 year ago

1.1.6

12 months ago

1.0.7

1 year ago

1.1.5

12 months ago

1.0.6

1 year ago

1.3.2

11 months ago

1.1.4

12 months ago

1.3.1

11 months ago

1.1.3

12 months ago

1.3.0

11 months ago

1.1.2

12 months ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago