s3pp

package module
v0.0.0-...-e49d3f2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: MIT Imports: 7 Imported by: 0

README

Build Status

s3pp

A package to help you create POST policies to upload files directly to Amazon S3, see the AWS docs for the all the available conditions and values.

Example

A working example is available in examples/form.go, below are the relevant parts:

form, err := s3pp.New(s3pp.Config{
        AWSCredentials: s3pp.AWSCredentials{
                AccessKeyID:     "key",
                SecretAccessKey: "secret",
        },
        Bucket:  "mybucket",
        Region:  "us-east-1",
        Expires: 10 * time.Minute,
        Key:     s3pp.Match("key", uuid.New()),
        Conditions: []s3pp.Condition{
                s3pp.Match("acl", "public-read"),
                s3pp.Match("success_action_status", "201"),
                s3pp.ContentLengthRange(1, 55000),
        },
})

form.Fields will contain all the fields generated from the conditions for the form and you can pass any additional conditions in Conditions. Available conditions are documented here: Creating a POST Policy.

The form:

<form action="{{.Action}}" method="POST" enctype="multipart/form-data">
  {{range $name, $value := .Fields}}
    <input type="text" name="{{$name}}" value="{{$value}}" readonly>
  {{end}}

  <input type="file" name="file">
  <input type="submit" value="Upload">
</form>

Documentation

Overview

Package s3pp creates POST policies for uploading files directly to Amazon S3. See: http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSCredentials

type AWSCredentials struct {
	AccessKeyID     string
	SecretAccessKey string
}

type Condition

type Condition interface {
	Name() string
	Value() string
}

func Any

func Any(field string) Condition

Any returns a condition where field can have any content. Fields created from this Condition return an empty string from Value.

func ContentLengthRange

func ContentLengthRange(min, max int64) Condition

ContentLengthRange specifies the minimum and maximum allowable size for the uploaded content. This condition is excluded from Fields.

func Match

func Match(field, value string) Condition

Match returns a condition where the field must match value. Fields created from this Condition return value from Value.

func StartsWith

func StartsWith(field, value string) Condition

StartsWith returns a condition where field must start with value. Fields created from this Condition return value from Value.

type Config

type Config struct {
	AWSCredentials AWSCredentials
	Bucket         string
	Region         string
	Expires        time.Duration
	Key            Condition
	Conditions     []Condition
}

type Form

type Form struct {
	Action string `json:"action"`

	// name -> value, generated from the Name and Value of the provided Conditions
	Fields map[string]string `json:"fields"`
}

func New

func New(c Config) (*Form, error)

New encodes and signs the POST Policy using AWS Signature v4 and returns the required fields to create a form for the POST request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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