awss3

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 15 Imported by: 0

README

AWS-S3

aws-s3 provides abstractions for using Amazon Simple Storage Service.

Calling storage.Open creates an S3Storage object. The urlString should be in the form asws3://bucket/prefix?region=&accept=&auto-create=false&acl=public-read

The URL parameters accepted are as follows:

  • region: region where the bucket is created. Default us-east-1
  • accept: comma-separated list of file extensions to accept. Could be repeated. e.g. url://bucket/prefix?accept=.jpeg,.svg&accept=.png would accept .jpeg, .svg and .png files. Default .jgp,.jpeg,.png,.svg
  • auto-create: will NOT create the bucket automatically if this value is any of: 0, off, disable, false.
  • acl: canned ACL policy for file uploads. See the documentation on Canned ACLs for details. Default public-read.

Usage

package main

import (
	"fmt"
    "strings"

	"github.com/djangulo/go-storage"
	_ "github.com/djangulo/go-storage/providers/aws-s3"
)

func main() {
	// upload to s3 bucket "my-bucket", under "my-prefix"
	// This assumes you've configured your credentials in ~/.aws/credentials
	drv, err := storage.Open("awss3://my-bucket/my-prefix?&accept=.txt")
	if err != nil {
		panic(err)
    }

    // file will be saved to .../my-prefix/my-file.txt
    url, err := drv.AddFile(strings.NewReader("my file contents"), "my-file.txt")
	// handle err
    fmt.Println(url)
    // Output: https://my-bucket.s3.us-east-1.amazonaws.com/my-prefix/my-file.txt
    err = drv.RemoveFile("my-file.txt")
    // handle err
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrURLParse = errors.New("awss3: error parsing url")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	AutoBucketCreate bool
	Region           string
	Bucket           string
	Prefix           string
	FileACL          string
	// contains filtered or unexported fields
}

type S3Storage

type S3Storage struct {
	// contains filtered or unexported fields
}

func (*S3Storage) Accepts

func (s *S3Storage) Accepts(ext string) (accepts bool)

func (*S3Storage) AddFile

func (s *S3Storage) AddFile(r io.Reader, p string) (string, error)

func (*S3Storage) Close

func (s *S3Storage) Close() error

Close noop

func (*S3Storage) DeleteContainer

func (s *S3Storage) DeleteContainer() (err error)

func (*S3Storage) EmtpyContainer

func (s *S3Storage) EmtpyContainer() error

func (*S3Storage) GetFile

func (s *S3Storage) GetFile(p string) (io.ReadCloser, error)

func (*S3Storage) NormalizePath

func (s *S3Storage) NormalizePath(entries ...string) string

func (*S3Storage) Open

func (s *S3Storage) Open(urlString string) (storage.Driver, error)

Open creates an S3Storage. The urlString should be in the form asws3://bucket/prefix?region=&accept=&auto-create=false&acl=public-read The URL parameters accepted are as follows:

  • region: region where the bucket is created. Default "us-east-1"
  • accept: comma-separated list of file extensions to accept. Could be repeated. e.g. url://bucket/prefix?accept=.jpeg,.svg&accept=.png would accept .jpeg, .svg and .png files. Default .jgp,.jpeg,.png,.svg
  • auto-create: will NOT create the bucket automatically if this value is any of: 0, off, disable, false.
  • acl: canned ACL policy for file uploads. See https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL for details. Default "public-read".

func (*S3Storage) Path

func (s *S3Storage) Path() string

func (*S3Storage) RemoveFile

func (s *S3Storage) RemoveFile(p string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL