Socket
Book a DemoInstallSign in
Socket

aws-s3-uploaders

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-s3-uploaders

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

aws-s3-uploaders


S3 compatible file uploader Plugin for Vite

NPM version NPM Downloads
GitHub stars

🚀 Features

  • S3 Compatible: Support any S3 compatible provider (AWS, DO Spaces...)
  • Uploads any files: can upload any files or directory not just build folder

📦 Install

$ npm i aws-s3-uploaders

🦄 Usage

uploadOptions default to ACL: 'public-read' so you may need to override if you have other needs.

Add vite-plugin-s3 plugin to vite.config.js / vite.config.ts and configure it:

import { AwsS3Uploader } from 'aws-s3-uploaders';

const uploader = AwsS3Uploader({
      basePath: '/build',
      clientConfig: {
        credentials: {
          accessKeyId: '',
          secretAccessKey: '',
        },
        region: 'eu-west-2',
      },
      uploadOptions: {
        Bucket: 'my-bucket',
      },
    }),
  ],
});

uploader.apply();

👀 Options

OptionDescriptionTypeDefault
excludeA Pattern to match for excluded contentstring,RegExp,Function,Arraynull
includeA Pattern to match for included contentstring,RegExp,Function,Arraynull
clientConfigThe configuration interface of S3Client class constructorS3ClientConfigrequired
uploadOptionsPutObjectRequest options except Body and `Key'PutObjectRequestrequired
basePathNamespace of uploaded files on S3stringnull
directoryDirectory to uploadstringnull

Advanced include and exclude rules

include and exclude in addition to a RegExp you can pass a function which will be called with the path as its first argument. Returning a truthy value will match the rule. You can also pass an Array of rules, all of which must pass for the file to be included or excluded.

import { AwsS3Uploader } from 'aws-s3-uploaders';
import isGitIgnored from 'is-gitignored';
// Up to you how to handle this
var isPathOkToUpload = function (path) {
  return require('my-projects-publishing-rules').checkFile(path);
};

const uploader = AwsS3Uploader({
  // Only upload css and js and only the paths that our rules database allows
  include: [
    /.*\.(css|js)/,
    function (path) {
      isPathOkToUpload(path);
    },
  ],
  // function to check if the path is gitignored
  exclude: isGitIgnored,
  clientConfig: {
    credentials: {
      accessKeyId: process.env.AWS_ACCESS_KEY_ID,
      secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    },
    region: 'eu-west-2',
  },
  uploadOptions: {
    Bucket: 'my-bucket',
  },
});

uploader.apply();

💧 DigitalOcean Spaces Object Storage example

import { AwsS3Uploader } from 'aws-s3-uploaders';

const uploader = AwsS3Uploader({
  clientConfig: {
    credentials: {
      accessKeyId: process.env.DO_ACCESS_KEY_ID,
      secretAccessKey: process.env.DO_SECRET_ACCESS_KEY,
    },
    endpoint: 'https://fra1.digitaloceanspaces.com',
    region: 'fra1',
  },
  uploadOptions: {
    Bucket: 'my-bucket',
  },
});

uploader.apply();

FAQs

Package last updated on 09 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts