# @losttracker/s3-uploader

> Package to upload compressed files to AWS S3

Latest version **1.0.4** (published 2021-03-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @losttracker/s3-uploader
pnpm add @losttracker/s3-uploader
yarn add @losttracker/s3-uploader
bun add @losttracker/s3-uploader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-03-19 |
| First published | 2020-08-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | yuvraj2112@gmail.com |
| Maintainers | losttracker |
| Keywords | s3, aws, file, upload, pako, compressed, chunks, form, multipart, stream |

## Links

- npm: https://www.npmjs.com/package/@losttracker/s3-uploader
- Repository: https://github.com/yuvraj2112/s3-uploader
- Homepage: https://github.com/yuvraj2112/s3-uploader#readme
- Issues: https://github.com/yuvraj2112/s3-uploader/issues
- npm.io page: https://npm.io/package/@losttracker/s3-uploader

## Dependencies (3)

- [pako](https://npm.io/package/pako.md) ^1.0.11
- [busboy](https://npm.io/package/busboy.md) ^0.3.1
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.825.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2021-03-19
- 1.0.3 — 2021-01-12
- 1.0.2 — 2021-01-12
- 1.0.1 — 2020-11-01
- 1.0.0 — 2020-08-22

## README

# s3-uploader

# Description
A node.js module to upload files to your S3 bucket. It also allows upload of files compressed using Pako after decompressing

# Install
```
npm install @losttracker/s3-uploader
```

## Example
```
const s3Uploader = require('@losttracker/s3-uploader');

const awsCredentials = {
  "region" : "us-west-2",
  "accessKeyId" : "access_key_id",
  "secretAccessKey" : "secret_access_key",
};
const bucket = 'fileuploads_bucket';

// to change file name or edit path. See uploadUrlGen below to know the list of
// parameters passed to method
const uploadUrlGen = (params) => {
  return 'trial_up/' + params.fields.formDataParam + params.filename;
};

const uploadDetails = await s3Uploader({request: req, bucket, awsCredentials, uploadUrlGen});
```

# API
The module returns a promise. The result is an array of responses from S3 upon successful file uploads.

### S3-uploader method
The method accepts an object with the following keys:
| Name      | Type    | Parameters/Properties       | Description |
|-----------|---------|-----------------------------|-------------|
| Request   | Object  | -                           | The incoming request object|
|s3_instance* | <S3 Object> | -                       | You can create an s3 instance using the aws-sdk and pass it as a parameter |
|awsCredential* | Object | region,  accessKeyId, secretAccessKey | The object must contain valid credentials required to connect to S3 instance |
| bucket    | string   | -                          | Valid S3 Bucket to upload the file to |
| mimeFilter | Method  | (mimetype, file_extension) <Return:bool>   | A method that will be passed mime and file extension. Can be used to filter files and stop upload progress. Return < True > when file is supported. |
| compressed | boolean | -                          | If using pako to compress. Default: false. |
| compressionRatio | number (1-9) | -                          | If using Pako, compression ratio to be used. Default: 1. |
| uploadUrlGen | Method | ({fields**, mimetype, bucket, filename}) <Returns: string> | This method can be used to programatically calculate the `key` to upload files to in your S3 bucket |
| maxSize   | number   | -                          | The maximum file size that can be uploaded. Default: null (unlimited) |
| s3UploadParams | Object | -                       | Any additional settings to be passed to the s3.upload method while uploading. Example: Metadata. For more information see: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property |
| busboyParams | Object | -                         | Any additional settings to be passed to the busboy constructor. Example: HWM. For more information see: https://www.npmjs.com/package/busboy#busboy-methods |

_* Any one of these 2 parameters is necessary_

_**it contains the parameters appended to formdata as an object_

Please contact me on **yuvraj2112@gmail.com** for any suggestions!

---
_Source: https://npm.io/package/@losttracker/s3-uploader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
