upload

package
v0.0.0-...-07cd16e Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCtype = "video/mp4"
	DefaultAcl   = "private"
)

Variables

View Source
var CreatorFn func(UploadParameters) (AwsUploadF, error)

Functions

func BucketOfUploadAction

func BucketOfUploadAction(actionURL string) (string, error)

bucketOfUploadAction parses an "action" URL as received with GetUploadInfo, and returns the bucket name part of that URL.

Example:

const a = "https://synqfm.s3.amazonaws.com"

bucket, err := bucketOfUploadAction(a)
if err != nil {
        log.Fatal(err)
}
fmt.Println(bucket) // prints synqfm

func ReformatXAmzDate

func ReformatXAmzDate(in string) (string, error)

ReformatXAmzDate reformats the contents of a X-Amz-Date header into the format that https://uploader.synq.fm/uploader/signature expects.

Example:

const in = "20060102T150405Z"

out, err := ReformatXAmzDate(in)
if err != nil {
        log.Fatal(err)
}
fmt.Println(out) // Mon, 02 Jan 2006 15:04:05 UTC

func RegionOfUploadAction

func RegionOfUploadAction(actionURL string) (string, error)

regionOfUploadAction parses an "action" URL as received with GetUploadInfo, and returns the region of the bucket that is the URL refers to.

This relies on heuristics, and will not work with certain styles of URLs.

See: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

Example:

const a = "https://synqfm.s3.amazonaws.com"

region, err := regionOfUploadAction(a)
if err != nil {
        log.Fatal(err)
}
fmt.Println(region) // prints us-east-1

func RewriteXAmzDateHeader

func RewriteXAmzDateHeader(h http.Header) error

RewriteXAmzDateHeader rewrites the X-Amz-Date header, of an http.Header, into the format that https://uploader.synq.fm/uploader/signature expects.

Example:

h := http.Header{}
h.Set("X-Amz-Date", "20060102T150405Z")

err := RewriteXAmzDateHeader(h)
if err != nil {
        log.Fatal(err)
}
fmt.Println(h.Get("X-Amz-Date")) // Mon, 2 Jan 2006 15:04:05 UTC

func TokenOfUploaderURL

func TokenOfUploaderURL(uploaderURL string) (string, error)

TokenOfUploaderURL parses an uploader URL string, and returns its token parameter.

Example:

const u = "https://uploader.synq.fm/uploader/" +
"00000000000000000000000000000000" +
"?token=11111111111111111111111111111111"

token, err := TokenOfUploaderURL(u)
if err != nil {
        log.Fatal(err)
}
fmt.Println(token) // prints 11111111111111111111111111111111

Types

type AwsUpload

type AwsUpload struct {
	UploadParams UploadParameters
	Uploader     *s3manager.Uploader
}

This is the struct that contains all the AWS settings

func (*AwsUpload) Acl

func (a *AwsUpload) Acl() string

func (*AwsUpload) AwsKeyId

func (a *AwsUpload) AwsKeyId() string

func (*AwsUpload) ContentType

func (a *AwsUpload) ContentType() string

func (AwsUpload) GetBucket

func (a AwsUpload) GetBucket() (string, error)

bucketOfUploadAction parses an "action" URL as received with GetUploadInfo, and returns the bucket name part of that URL.

Example:

const a = "https://synqfm.s3.amazonaws.com"

bucket, err := bucketOfUploadAction(a)
if err != nil {
        log.Fatal(err)
}
fmt.Println(bucket) // prints synqfm

func (AwsUpload) GetRegion

func (a AwsUpload) GetRegion() (string, error)

regionOfUploadAction parses an "action" URL as received with GetUploadInfo, and returns the region of the bucket that is the URL refers to.

This relies on heuristics, and will not work with certain styles of URLs.

See: http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

Example:

const a = "https://synqfm.s3.amazonaws.com"

region, err := regionOfUploadAction(a)
if err != nil {
        log.Fatal(err)
}
fmt.Println(region) // prints us-east-1

func (*AwsUpload) Key

func (a *AwsUpload) Key() string

func (*AwsUpload) Request

func (a *AwsUpload) Request(body []byte) ([]byte, error)

func (*AwsUpload) ServerSignV2

func (a *AwsUpload) ServerSignV2(r *request.Request) (string, error)

func (*AwsUpload) SignRequest

func (a *AwsUpload) SignRequest(r *request.Request) error

This runs as a handler within the Sign HandlerList and uses unicorn to sign the request This will replace whats in awssdk-go/aws/signer/v4/v4.go and its own "signWithBody" method https://docs.aws.amazon.com/general/latest/gr/signature-version-2.html https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html

func (AwsUpload) Signer

func (a AwsUpload) Signer() func(r *request.Request)

func (*AwsUpload) Upload

func (a *AwsUpload) Upload(body io.Reader) (*s3manager.UploadOutput, error)

func (*AwsUpload) UploaderSigUrl

func (a *AwsUpload) UploaderSigUrl() string

func (*AwsUpload) Url

func (a *AwsUpload) Url() string

func (*AwsUpload) V4Sig

func (a *AwsUpload) V4Sig(req V4Request) (resp V4Response, err error)

type AwsUploadF

type AwsUploadF interface {
	Upload(io.Reader) (*s3manager.UploadOutput, error)
}

func NewAwsUpload

func NewAwsUpload(params UploadParameters) (AwsUploadF, error)

UploadParameters is retrieved from the Unicorn API, so we're creating an AwsUpload from the settings

type UploadParameters

type UploadParameters struct {
	Action         string `json:"action"`
	AwsAccessKeyId string `json:"AWSAccessKeyId"`
	ContentType    string `json:"Content-Type"`
	Policy         string `json:"policy"`
	Signature      string `json:"signature"`
	Acl            string `json:"acl"`
	Region         string `json:"region"`
	Key            string `json:"key"`
	SuccessStatus  string `json:"success_action_status"`
	SignatureUrl   string `json:"signature_url"`
	VideoId        string `json:"video_id"`
	AssetId        string `json:"asset_id"`
}

type UploadRequest

type UploadRequest struct {
	AssetId     string `json:"asset_id"`
	ContentType string `json:"content_type"`
	Ext         string `json:"ext"`
	Type        string `json:"type"`
	Acl         string `json:"acl"`
}

func NewUploadRequest

func NewUploadRequest(data []byte) (UploadRequest, error)

func (UploadRequest) GetAcl

func (u UploadRequest) GetAcl() string

func (UploadRequest) GetCType

func (u UploadRequest) GetCType() string

func (UploadRequest) GetExt

func (u UploadRequest) GetExt() string

func (UploadRequest) GetType

func (u UploadRequest) GetType() string

func (*UploadRequest) ProcessCtype

func (u *UploadRequest) ProcessCtype() error

type UploaderSignatureRequest

type UploaderSignatureRequest struct {
	Headers string `json:"headers"`
}

UploaderSignatureRequest is the request that is sent when using the embeddable web uploader's request signing service.

type UploaderSignatureResponse

type UploaderSignatureResponse struct {
	Signature string `json:"signature"`
}

UploaderSignatureResponse is the response that is received when using the embeddable web uploader's request signing service.

type V4Request

type V4Request struct {
	Method   string            `json:"method"`
	Action   string            `json:"action"`
	Path     string            `json:"path"`
	Region   string            `json:"region"`
	RawQuery string            `json:"raw_query"`
	Headers  map[string]string `json:"headers"`
}

func CreateV4Request

func CreateV4Request(params UploadParameters, req *request.Request) V4Request

func (*V4Request) BuildRequest

func (r *V4Request) BuildRequest() *http.Request

func (*V4Request) Sign

func (r *V4Request) Sign(awsKey, awsSecret string) (resp V4Response, err error)

type V4Response

type V4Response struct {
	Authorization string `json:"authorization"`
	Date          string `json:"date"`
}

Jump to

Keyboard shortcuts

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